Next: Object reference predicates, Previous: Promises, Up: Objects [Contents][Index]
Like $
, but to-refr may be near or far, and
<-
returns a promise instead of a result.
(define object-a (spawn ^some-object)) ;; in a different vat... or the same; it doesn't matter to <- (define a-promise (<- object-a arg1)) (define b-promise (<- object-a 'some-method arg2))
<-
has a variant that does not return a promise:
Like <-
, but return void
instead of a promise.
(define object-a (spawn ^some-object)) ;; in a different vat... or the same; it doesn't matter to <-np (<-np object-a arg1) ; returns void (<-np object-a 'some-method arg2) ; returns void
Like <-np
, but only operate on far objects.
This procedure can be used outside of a vat.
Goblins provides two primary tools for resolving and operating on
promise values, on
and listen-to
. Neither pauses
program execution, so code following their invocation is conceptually
concurrent with their various handlers. These handlers therefore
constitute the asynchronous logic of most Goblins programs.
Respond to a promise, optionally with error handling. Return nothing
unless promise? is #t
, in which case return a promise.
As mentioned above, if #:promise?
is #t
, then on
will itself return a promise. This promise is resolved as follows:
vow
is fulfilled and fulfilled-handler
is not
provided, the promise returned will share vow
’s resolution.
vow
is fulfilled and fulfilled-handler
is provided,
the resolution will be whatever is returned from
fulfilled-handler
, unless fulfilled-handler
raises an
error, in which case the promise will be broken with its error-value
set to this exception.
vow
is broken and catch
is not provided, the promise
returned will share vow
’s broken result.
vow
is broken and catch
is provided, the resolution
will be whatever is returned from catch
, unless catch
raises an error, in which case the promise will be broken with its
error-value set to this exception (which may even be the original
exception).
;; in the context of some vat (define object-a (spawn ^some-object)) ;; in the context of some vat, possibly different (on (<- object-a arg1) (lambda (val) (some-proc val)) #:catch (lambda (err) (handle-err err)) #:finally (lambda _ (other-proc)) #:promise? #f) ; the default, written out for demonstration
Goblins also exposes a more primitive interface to listen for promise resolution, mostly useful if you don’t need to know the value a resolved promise and just want to know that it has resolved:
Wait for to-refr, a promise, to resolve, then call
listener with its value. If wants-partial? is #t
,
return updates rather than waiting for full promise resolution.
The value passed to listener is a list of the form
('fulfill val)
on success, where val is the result of
resolving to-refr; or of the form ('break problem)
on
failure, where problem is the cause of a failed computation.
Next: Object reference predicates, Previous: Promises, Up: Objects [Contents][Index]