tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

forkAwait.tri (489B)


      1 !import "prelude" !Local
      2 !import "io"      !Local
      3 
      4 -- Basic fork and await.
      5 -- fork spawns a concurrent task and returns a handle.
      6 -- await blocks until the task completes and returns its value.
      7 
      8 worker = msg :
      9   bind (putStrLn (append "working: " msg)) (_ :
     10   pure (append msg "-result"))
     11 
     12 main = io <|
     13   (bind (fork (worker "job1")) (h1 :
     14   bind (fork (worker "job2")) (h2 :
     15   bind (await h1) (r1 :
     16   bind (await h2) (r2 :
     17   putStrLn (append "Got " (append r1 (append " and " r2))))))))