Created
December 11, 2022 03:35
-
-
Save jfrederickson/a155a75b5a42039686741a804b9e2b7c to your computer and use it in GitHub Desktop.
async goblins to sync call-return semantics via channels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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