Next: Methods, Previous: Joiners, Up: actor-lib: A standard library of sorts [Contents][Index]
The (goblins actor-lib let-on)
module provides convenient
syntax to facilitate promise pipelining.
Syntax sugar around on
, all-of
, lambda
, and
match-lambda
to allow using promise pipelining with a
let
-like syntax. Each exp (an asynchronous invocation of
an actor resulting in a promise) is evaluated concurrently; the
resulting promises are bound to their corresponding vars; and
finally body is evaluated in an environment where all promises
are resolved.
For example, this use of let-on
…
(define (^doubler bcom) (lambda (x) (* x 2))) (define doubler (spawn ^doubler)) (let-on ((four (<- doubler 2)) (eight (<- doubler 4))) (+ four eight))
…is equivalent to…
(use-modules (goblins actor-lib joiners)) (on (all-of (<- doubler 2) (<- doubler 4)) (match-lambda* ((four eight) (+ four eight))))
Like let-on
, except paralleling let*
; each exp is
resolved sequentially rather than concurrently, and each
var
is available in the body of the succeeding exps.
This is equivalent to nested on
and lambda
calls, without
using match-lambda
or all-of
.
So this use of let*-on
…
(let*-on ((four (<- doubler 2)) (eight (<- doubler four))) (+ four eight))
…is equivalent to…
(on (<- doubler 2) (lambda (four) (on (<- doubler four) (lambda (eight) (+ four eight)) #:promise? #t)) #:promise? #t)