hphp/hack/manual/hsl/Classes/HH.Lib.Async/Semaphore/index.md
:::info[Note] This is a point-in-time snapshot of the API documentation from January 2026. Going forward, we will not be maintaining a public copy of these references, and recommend users to refer to the built-in signature helpers available in the Hack LSP instead for complete and up-to-date information. :::
Run an operation with a limit on number of ongoing asynchronous jobs
All operations must have the same input type (Tin) and output type (Tout),
and be processed by the same function; Tin may be a callable invoked by the
function for maximum flexibility, however this pattern is best avoided in favor
of creating semaphores with a more narrow process.
Use genWaitFor() to retrieve a Tout from a Tin.
namespace HH\Lib\Async;
final class Semaphore {...}
->__construct(int $concurrentLimit, (function(Tin): Awaitable<Tout>) $f)->waitForAsync(Tin $value): Awaitable<Tout>Tout from a Tin, respecting the concurrency limit