> $iterable Iterator or array to iterate over. * @param (callable(TValue, TKey, PromiseInterface): mixed)|null $onFulfilled * @param (callable(TReason, TKey, PromiseInterface): mixed)|null $onRejected * @param array{concurrency?: int|(callable(int): int)} $config Configuration options. * * @return PromiseInterface */ public static function of( iterable $iterable, ?callable $onFulfilled = null, ?callable $onRejected = null, array $config = [] ): PromiseInterface { $eachConfig = []; if (null !== $onFulfilled) { $eachConfig['fulfilled'] = $onFulfilled; } if (null !== $onRejected) { $eachConfig['rejected'] = $onRejected; } if (isset($config['concurrency'])) { $eachConfig['concurrency'] = $config['concurrency']; } return (new EachPromise($iterable, $eachConfig))->promise(); } /** * Like of, but only allows a certain number of outstanding promises at any * given time. * * $concurrency may be an integer or a function that accepts the number of * pending promises and returns a numeric concurrency limit value to allow * for a dynamic concurrency size. * * @template TKey of array-key * @template TValue * @template TReason * * @param iterable> $iterable * @param int|(callable(int): int) $concurrency * @param (callable(TValue, TKey, PromiseInterface): mixed)|null $onFulfilled * @param (callable(TReason, TKey, PromiseInterface): mixed)|null $onRejected * * @return PromiseInterface */ public static function ofLimit( iterable $iterable, $concurrency, ?callable $onFulfilled = null, ?callable $onRejected = null ): PromiseInterface { return self::of($iterable, $onFulfilled, $onRejected, ['concurrency' => $concurrency]); } /** * Like ofLimit, but rejects the aggregate promise on the first rejection. * * @template TKey of array-key * @template TValue * @template TReason * * @param iterable> $iterable * @param int|(callable(int): int) $concurrency * @param (callable(TValue, TKey, PromiseInterface): mixed)|null $onFulfilled * * @return PromiseInterface */ public static function ofLimitAll( iterable $iterable, $concurrency, ?callable $onFulfilled = null ): PromiseInterface { return self::ofLimit( $iterable, $concurrency, $onFulfilled, function ($reason, $idx, PromiseInterface $aggregate): void { $aggregate->reject($reason); } ); } }