You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guides/asynchronous-tasks/readme.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,20 +143,23 @@ end
143
143
144
144
### Waiting for the First N Tasks
145
145
146
-
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:
146
+
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:
147
147
148
148
```ruby
149
-
barrier=Async::Barrier.new(parent: barrier)
149
+
waiter=Async::Waiter.new(parent: barrier)
150
150
151
151
Asyncdo
152
152
jobs.each do |job|
153
-
barrier.async do
153
+
waiter.async do
154
154
# ... process job ...
155
155
end
156
156
end
157
157
158
158
# Wait for the first two jobs to complete:
159
-
done = barrier.wait(2)
159
+
done = waiter.wait(2)
160
+
161
+
# You may use the barrier to stop the remaining jobs
0 commit comments