Concurrent.SchedulerSourcetype ('resource, 'scope_ctx, 'concurrent_ctx) spawn_fn =
'scope_ctx Concurrent__.Types.Scope.t @ local ->
('scope_ctx Concurrent__.Types.Scope.Task_handle.t @ local unique ->
'concurrent_ctx @ local ->
'concurrent_ctx Concurrent__.Types.concurrent @ local portable ->
'resource @ unique once portable contended ->
Base.unit)
Concurrent__.Types.task @ once portable ->
'resource @ unique once portable contended ->
'resource Concurrent__.Types.spawn_result @ unique once portable contendedScheduler.t is the type representing a handle to a concurrent scheduler. A handle to the scheduler allows spawning unstructured concurrent tasks.
val create :
'concurrent_ctx. spawn:
(('resource : value_or_null) 'scope_ctx. ('resource,
'scope_ctx,
'concurrent_ctx)
spawn_fn) ->
'concurrent_ctx tcreate ~spawn creates a new scheduler with the given spawn function.
val with_context :
'ctx1 t @ portable ->
('ctx1 @ local ->
'ctx1 concurrent @ local portable ->
f:('ctx2 @ local -> Base.unit) @ local once ->
Base.unit) @ portable ->
'ctx2 t @ portablewith_context t ctx is a scheduler enriched with the new context-building function ctx, which is called on all spawned concurrent tasks with both the new Concurrent.t and the old context, in addition to a callback for the new context.
val spawn :
'concurrent_ctx t @ local ->
'scope_ctx Scope.t @ local ->
('scope_ctx Concurrent__.Types.Scope.t @ local ->
('concurrent_ctx @ local ->
('concurrent_ctx t @ local portable ->
Base.unit @ portable contended) @ local once) @ local once)
Task.t @ once portable ->
Base.unitspawn scheduler scope task spawns a new concurrent task into the given scope to execute the given task using the scheduler scheduler.
val spawn_with :
'concurrent_ctx t @ local ->
'scope_ctx Scope.t @ local ->
('scope_ctx Scope.t @ local ->
('concurrent_ctx @ local ->
('concurrent_ctx concurrent @ local portable ->
('resource @ unique once portable contended ->
Base.unit) @ local once) @ local once) @ local once)
Task.t @ once portable ->
'resource @ unique once portable contended ->
'resource spawn_result @ unique once portable contendedspawn_with scheduler task resource spawns a new concurrent task to execute the given task, using the scheduler scheduler providing it with some unique resource
The resource is guaranteed to either be passed to f, or returned as part of the Failed spawn_result to be handled by the caller.
val spawn_daemon :
'concurrent_ctx t @ local ->
'scope_ctx Scope.t @ local ->
('scope_ctx Concurrent__.Types.Scope.t @ local ->
(Await.Cancellation.t @ local ->
('concurrent_ctx @ local ->
('concurrent_ctx t @ local portable ->
Base.unit Await.Or_canceled.t @ portable contended) @ local once) @ local once) @ local once)
Task.t @ once portable ->
Base.unitspawn_daemon scheduler scope task spawns a concurrent daemon task executing f into the given scope. Daemon tasks are given a cancellation token which is canceled once the outer scope and all non-daemon tasks spawned into it finish.
If the scope is terminated due to an exception, daemon tasks are terminated rather than canceled.
val spawn_daemon' :
'concurrent_ctx t @ local ->
'scope_ctx Scope.t @ local ->
('scope_ctx Scope.t @ local ->
(Await.Cancellation.t @ local ->
('concurrent_ctx @ local ->
('concurrent_ctx concurrent @ local portable ->
Base.unit) @ local once) @ local once) @ local once)
Task.t @ once portable ->
Base.unitspawn_daemon' is like spawn_daemon, except the task function it expects returns unit instead of unit Or_canceled.t.