Skip to content

Instantly share code, notes, and snippets.

@jfrederickson
Created December 11, 2022 03:35
Show Gist options
  • Save jfrederickson/a155a75b5a42039686741a804b9e2b7c to your computer and use it in GitHub Desktop.
Save jfrederickson/a155a75b5a42039686741a804b9e2b7c to your computer and use it in GitHub Desktop.
async goblins to sync call-return semantics via channels
(use-modules
(goblins)
(goblins actor-lib methods)
(fibers)
(fibers channels))
(define main-vat (spawn-vat))
(define-vat-run main-run main-vat)
(define remote-vat (spawn-vat))
(define-vat-run remote-run remote-vat)
(define (^hello bcom)
(lambda ()
"Hello world!"))
(define hello (remote-vat (lambda () (spawn ^hello))))
(define (^test bcom)
(methods
[(test friend channel)
(on (<- friend)
(lambda (ret)
(put-message channel ret)))]))
(define test (main-vat (lambda () (spawn ^test))))
(define (async-to-sync)
(define ret-channel (make-channel))
(main-run ($ test 'test hello ret-channel))
(get-message ret-channel))
(display (async-to-sync))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment