-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Async\Semaphore
to wait for different types
#166
Comments
Another idea is to use final class Semaphore {
public function __construct(
private int $concurrentLimit,
);
public function aquireWorkerAsync(): Awaitable<IAsyncDisposable>;
} // Usage
$worker_pool = new Semaphore(2);
async function my_script(vec<string> $files_to_lint): Awaitable<void> {
$lint_results = Vec\map(
$files_to_lint,
$file ==> {
await using($_worker = await $worker_pool->aquireWorkerAsync()) {
return call_hh_client_linter($file);
}
}
);
} This approach is better than the closure approach because it could keep the call stack clean. In the closure approach, when an exception is thrown from the closure, the call stack would be noisy and hard to debug. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use
Async\Semaphore
to limit the concurrency in hhvm/hhast#399, which works good. But the current design ofAsync\Semaphore
does not support the use cases where thewaitForAsync
callers expect different types. I wonder if we could support the following type signature, so that we can use the sameSemaphore
limit the concurrency of heterogeneous job types.The text was updated successfully, but these errors were encountered: