Async_kernel.ThrottledSourceAn 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.
include Core.Applicative with type 'a t := 'a tval return : 'a -> 'a tmodule Applicative_infix : sig ... endjob 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.
run t takes a Throttled type and runs it.
of_thunk thunk converts a function of type unit -> 'a t to type 'a t. Useful for delaying computation.
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.