tricu

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

forkAwait.tri (480B)


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