Files
tricu/demos/interactionTrees/forkAwait.tri
2026-05-16 14:59:52 -05:00

19 lines
547 B
Plaintext

!import "../../lib/base.tri" !Local
!import "../../lib/list.tri" !Local
!import "../../lib/io.tri" !Local
-- Basic fork and await.
-- fork spawns a concurrent task and returns a handle.
-- await blocks until the task completes and returns its value.
worker = msg :
bind (putStrLn (append "working: " msg)) (_ :
pure (append msg "-result"))
main = io <|
(bind (fork (worker "job1")) (h1 :
bind (fork (worker "job2")) (h2 :
bind (await h1) (r1 :
bind (await h2) (r2 :
putStrLn (append "Got " (append r1 (append " and " r2))))))))