Concurrent_in_asyncAn implementation of concurrency that uses Async to spawn concurrent tasks.
open Async
let result = Ivar.create ();;
Concurrent_in_async.schedule_with_concurrent Await.Terminator.never ~f:(fun conc ->
(* Create a new scope for concurrent tasks to be spawned in *)
Concurrent.with_scope conc () ~f:(fun s ->
(* [Concurrent.spawn_onto_initial] allows nonportable tasks to be spawned *)
Concurrent.spawn_onto_initial s ~f:(fun _ _ _c ->
Ivar.fill_exn result "hello from another concurrent task"))
[@nontail])The spawn options are interpreted as follows:
affinity: Ignoredname: Ignoredval schedule_with_concurrent :
?monitor:Async.Monitor.t ->
?priority:Async.Priority.t ->
Await.Terminator.t @ local ->
(f:
(Await.Capsule.Initial.k Await.Capsule.Access.boxed Concurrent.t @ local ->
'a) @ once ->
'a Async.Deferred.t) @ localschedule_with_concurrent terminator ~f schedules f conc to be run on the async scheduler, where conc is an implementation of concurrency which spawns tasks onto the async scheduler. The tasks are given access to the initial capsule, which allows them to run nonportable functions via Concurrent.spawn_onto_initial.
?monitor and ?priority, if passed, are forwarded onto Async.schedule
val scheduler :
?monitor:Async.Monitor.t ->
?priority:Async.Priority.t ->
unit ->
Await.Capsule.Initial.k Await.Capsule.Access.boxed Concurrent.Scheduler.tscheduler ?monitor ?priority () is a handle that allows spawning concurrent tasks in the Async scheduler.
val spawn_deferred :
('scope_ctx, Await.Capsule.Initial.k Await.Capsule.Access.boxed)
Concurrent.Spawn.t @ local ->
(f:
('scope_ctx Await.Scope.t @ local ->
(Await.Capsule.Initial.k Await.Capsule.Access.boxed @ local ->
(Await.Capsule.Initial.k Await.Capsule.Access.boxed Concurrent.t @ local ->
unit Async.Deferred.t) @ local once) @ local once) @ once ->
unit) @ localspawn_deferred spawn ~f spawns a deferred-returning task executing f scope access concurrent using spawn
module Portable : sig ... endCapabilities for submitting jobs to the async scheduler from other threads