Skip to content
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

Guide: LimitedBarrier was renamed to Waiter #231

Merged
merged 1 commit into from
May 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions guides/asynchronous-tasks/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,23 @@ end

### Waiting for the First N Tasks

Occasionally, you may need to just wait for the first task (or first several tasks) to complete. You can use a combination of {ruby Async::LimitedBarrier} and {ruby Async::Barrier} for controlling this:
Occasionally, you may need to just wait for the first task (or first several tasks) to complete. You can use a combination of {ruby Async::Waiter} and {ruby Async::Barrier} for controlling this:

```ruby
barrier = Async::Barrier.new(parent: barrier)
waiter = Async::Waiter.new(parent: barrier)

Async do
jobs.each do |job|
barrier.async do
waiter.async do
# ... process job ...
end
end

# Wait for the first two jobs to complete:
done = barrier.wait(2)
done = waiter.wait(2)

# You may use the barrier to stop the remaining jobs
barrier.stop
end
```

Expand Down