package async_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

An applicative type for concurrent computations with limited concurrency.

The computation takes place lazily and only when the run function is called.

Compared to how Throttle is typically used, this type lets you avoid an up-front time&memory cost of adding all concurrent jobs to the throttle. In particular you can implement a throttled traversal of a very large data structure without doing a synchronous walk over the entire structure at any given time.

module Deferred := Async_kernel__.Deferred1
type 'a t
include Core.Applicative with type 'a t := 'a t
val return : 'a -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

same as apply

val (<*) : 'a t -> unit t -> 'a t
val (*>) : unit t -> 'a t -> 'a t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Applicative_infix : sig ... end
val job : (unit -> 'a Deferred.t) -> 'a t

job f takes a function of type unit -> 'a Defferred.t and converts it to a Throttled type than can be executed with throttling using val run.

The function will be holding one throttle token while running.

val run : 'a t -> max_concurrent_jobs:int -> 'a Deferred.t

run t takes a Throttled type and runs it.

val of_thunk : (unit -> 'a t) -> 'a t

of_thunk thunk converts a function of type unit -> 'a t to type 'a t. Useful for delaying computation.

val both_unit : unit t -> unit t -> unit t

both_unit t1 t2 combines two unit t into one in a way that's more efficent by saving the mapping over the final deferred.

This optimization is important if t1 finishes early but t2 finishes late, since the memory usage between the two events is reduced to 0.

OCaml

Innovation. Community. Security.