[wg-parallel] About Lwt and Async

Mark Shinwell mshinwell at janestreet.com
Mon Apr 29 11:38:40 BST 2013


On 29 April 2013 11:18, Jeremie Dimino <jdimino at janestreet.com> wrote:
> Lwt and async also differs regarding Lwt.wait/Ivar.fill but there
> seems to be an agreement that the async's behavior is better and it is
> trivial to change in lwt so that shouldn't be an issue.

I might be misunderstanding something about Lwt here, but as far as I
see it, this latter point is quite important.  I believe one of the
most important features of Async is the fact that you cannot be
interrupted "between binds" by some arbitrary other job---whereas I
do not think that is the case with the Lwt semantics (as far as I know,
the equivalent to filling an ivar could cause something else to be
run immediately; is that correct?).

> Error handling
> --------------
>
> The ['a Lwt.t] type 'inline' the error monad [Value of 'a | Error of
> exn] while in async all errors are explicit.  So the async equivalent
> of ['a Lwt.t] would be [('a, exn) Result.t Deferred.t].
>
> As a result, while most functions in lwt return a [something Lwt.t],
> in async they return a variant or a [something Or_error.t Deferred.t]
> when the result may be an error status.

I think it's worth noting the [Monitor] construct of Async here,
which encapsulates jobs with wrappers to direct any exceptions they
might throw to appropriate places.

Mark


More information about the wg-parallel mailing list