I am trying to understand the term lwt supported
.
So assume I have a piece of code which connect a database and write some data: Db.write conn data
. It has nothing to do with lwt yet and each write will cost 10 sec
.
Now, I would like to use lwt. Can I directly code like below?
let write_all data_list = Lwt_list.iter (Db.write conn) data_list
let _ = Lwt_main.run(write_all my_data_list)
Support there are 5
data items in my_data_list
, will all 5 data items be written into the database sequentially or in parallel?
Also in Lwt manually or http://ocsigen.org/tutorial/application, they say
Using Lwt is very easy and does not cause troubles, provided you never use blocking functions (non cooperative functions). Blocking functions can cause the entre server to hang!
I quite don't understand how to not using blocking functions. For every my own function, can I just use Lwt.return
to make it lwt support
?