Affect is a streamlined and natural concurrency model for OCaml.
It provides parallel asynchronous functions and first-class synchronous actions to orchestrate them. The resulting concurency model has structured cooperative concurrency, structured cancellation and structured effect handling.
Warning. These APIs are still subject to change in the future, especially the private ones. Feedback and suggestions are welcome on the project's issue tracker.
The following manuals are available:
affectAsynchronous functions are made available in an extended Stdlib.Fun module.
Affect Asynchronous functions. Open to use it.Affect.Fun.Async Asynchronous functions.The Action module provides first-class synchronization (can be used independently). A few derived synchronization structures are provided.
Affect.Action First-class synchronous actions.Affect.Port Synchronous one-to-one rendezvous.Affect.Cell.Drop Drop cells.Affect.Cell.Lazy Lazy immutable cells.Affect.Cell.Once Set-once immutable cells.Affect.Semaphore Semaphores.affect.unixAffect_unix Cooperative operating system interaction. Open to use it.Affect_unix.Unix Unix module overriden with cooperative functions and actions.Affect_unix.Mtime Monotonic time.Affect_unix.Ptime POSIX time.affect.cliAffect_cli Cmdliner support for affected programs.affect.tmpThis library has unstable functionality that will be moved to another library in the future. It may still be useful if you are playing with affect.
Net Networking.open Affect
let main () =
Fun.Async.main @@ fun () ->
let f0 = Fun.Async.call (fun () -> 1) in
let f1 = Fun.Async.call (fun () -> 2) in
print_int (Fun.Async.get f0 + Fun.Async.get f1);
0
let () = if !Sys.interactive then () else exit (main ())See other blueprints in the cookbook.