Concurrent_in_asyncSourceAn implementation of concurrency that uses Async to spawn concurrent tasks.
open Async
let result = Ivar.create ();;
Concurrent_in_async.schedule_with_concurrent
Await.Terminator.unkillable
~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.tschedule_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 Concurrent.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 ->
unitspawn_deferred spawn ~f spawns a deferred-returning task executing f scope access concurrent using spawn
val spawn_join :
('a : value mod contended). ?monitor:Async.Monitor.t ->
'ctx Concurrent.Scheduler.t @ local ->
f:
('ctx @ local ->
('ctx Concurrent.t @ local portable ->
'a @ portable) @ local once) @ once portable ->
'a Async.Deferred.tspawn_join ?monitor sched ~f schedules f c to run on the scheduler sched and returns a Deferred.t that will become determined with its result.
If f raises, the exception is reported to the async monitor monitor, which defaults to the current monitor.