Closed aantron closed 6 years ago
This looks pretty interesting! what if we call run
at the beginning and have it return an exit
function that will terminate the loop?
The job of run
is to block the process from exiting until async code is all done, so if we call it at the beginning, nothing else after run
will ever run.
@aantron gotcha, then your change makes a ton of sense. I can test whenever you want :)
@kennetpostigo I committed it. It's now
Repromise_lwt.run: unit => unit;
Repromise_lwt.stop: unit => unit;
Right now, we have
https://github.com/aantron/repromise_lwt/blob/c7f4244799c393ee28b7539fcc4b7e0a9038f490/src/repromise_lwt.rei#L3
Ideally, we would make
run
behave like Node. It would berun: unit => unit
, and it would keep calling the main loop until there are both (1) no callbacks and (2) no pending I/O. We can tell when there are no callbacks by querying Repromise. However, there is currently no easy way to query Lwt for whether there is no pending I/O.So, I think the next-best thing is to create a global
Repromise.t(unit)
, and haverun: unit => unit
keep calling the main loop until this global promise is resolved. So, programs would look like:cc @kennetpostigo I think this API is less confusing than
~until
.