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
- `Async::Notification#signal` now returns `true` if a task was signaled, `false` otherwise, providing better feedback for notification operations.
6
+
7
+
### Async::Barrier Improvements
8
+
9
+
`Async::Barrier` now provides more flexible and predictable behavior for waiting on task completion:
10
+
11
+
-**Completion-order waiting**: `barrier.wait` now processes tasks in the order they complete rather than the order they were created. This provides more predictable behavior when tasks have different execution times.
12
+
-**Block-based waiting**: `barrier.wait` now accepts an optional block that yields each task as it completes, allowing for custom handling of individual tasks:
13
+
14
+
```ruby
15
+
barrier =Async::Barrier.new
16
+
17
+
# Start several tasks
18
+
3.times do |i|
19
+
barrier.async do |task|
20
+
sleep(rand*0.1) # Random completion time
21
+
"result_#{i}"
22
+
end
23
+
end
24
+
25
+
# Wait for all tasks, processing them as they complete
26
+
barrier.wait do |task|
27
+
result = task.wait
28
+
puts"Task completed with: #{result}"
29
+
end
30
+
```
31
+
32
+
-**Partial completion support**: The new block-based interface allows you to wait for only the first N tasks to complete:
33
+
34
+
```ruby
35
+
# Wait for only the first 3 tasks to complete
36
+
count =0
37
+
barrier.wait do |task|
38
+
task.wait
39
+
count +=1
40
+
breakif count >=3
41
+
end
42
+
```
43
+
44
+
This makes `Async::Barrier` a superset of `Async::Waiter` functionality, providing more flexible task coordination patterns.
45
+
46
+
### Queue Closing Functionality
47
+
48
+
`Async::Queue` and `Async::LimitedQueue` now support closing, which provides better resource management and error handling:
49
+
50
+
-**New `close` method**: Both queue types now have a `close` method that prevents further items from being added and signals any waiting tasks.
51
+
-**Consistent error handling**: All queue modification methods (`push`, `enqueue`, `<<`) now raise `Async::Queue::ClosedError` when called on a closed queue.
52
+
-**Waiting task signaling**: When a queue is closed, any tasks waiting on `dequeue` (for regular queues) or `enqueue` (for limited queues) are properly signaled and can complete.
53
+
54
+
```ruby
55
+
queue =Async::Queue.new
56
+
57
+
# Start a task waiting for items:
58
+
waiting_task =Asyncdo
59
+
queue.dequeue
60
+
end
61
+
62
+
# Close the queue - this signals the waiting task
63
+
queue.close
64
+
65
+
# These will raise Async::Queue::ClosedError
66
+
queue.push(:item) # => raises ClosedError
67
+
queue.enqueue(:item) # => raises ClosedError
68
+
queue <<:item# => raises ClosedError
69
+
70
+
# Dequeue returns nil when closed and empty
71
+
queue.dequeue # => nil
72
+
```
73
+
3
74
## v2.25.0
4
75
5
-
- Added support for `io_select` hook in the fiber scheduler, allowing non-blocking `IO.select` operations. This enables better integration with code that uses `IO.select` for multiplexing IO operations.
76
+
- Added support for `io_select` hook in the fiber scheduler, allowing non-blocking `IO.select` operations. This enables better integration with code that uses `IO.select` for multiplexing IO operations.
6
77
7
78
### Use `IO::Event::WorkerPool` for Blocking Operations
8
79
@@ -29,9 +100,9 @@ end
29
100
30
101
## v2.24.0
31
102
32
-
- Ruby v3.1 support is dropped.
33
-
-`Async::Wrapper` which was previously deprecated, is now removed.
34
-
-`Async::Barrier` now waits in order of completion rather than order of creation. This means that if you create a barrier with 3 tasks, and one of them completes (or fails) before the others, it will be the first to be yielded to the barrier.
103
+
- Ruby v3.1 support is dropped.
104
+
- `Async::Wrapper` which was previously deprecated, is now removed.
105
+
- `Async::Barrier` now waits in order of completion rather than order of creation. This means that if you create a barrier with 3 tasks, and one of them completes (or fails) before the others, it will be the first to be yielded to the barrier.
35
106
36
107
### Flexible Timeouts
37
108
@@ -63,7 +134,7 @@ end
63
134
64
135
## v2.23.0
65
136
66
-
- Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
137
+
- Rename `ASYNC_SCHEDULER_DEFAULT_WORKER_POOL` to `ASYNC_SCHEDULER_WORKER_POOL`.
67
138
68
139
### Fiber Stall Profiler
69
140
@@ -93,7 +164,7 @@ Ruby 3.4 will feature a new fiber scheduler hook, `blocking_operation_wait` whic
93
164
94
165
The Async scheduler optionally supports this feature using a worker pool, by using the following environment variable:
95
166
96
-
ASYNC_SCHEDULER_WORKER_POOL=true
167
+
ASYNC_SCHEDULER_WORKER_POOL=true
97
168
98
169
This will cause the scheduler to use a worker pool for general blocking operations, rather than blocking the event loop.
99
170
@@ -113,21 +184,21 @@ To take advantage of this feature, you will need to introduce your own `config/t
113
184
114
185
Occasionally on issues, I encounter people asking for help and I need more information. Pressing Ctrl-C to exit a hung program is common, but it usually doesn't provide enough information to diagnose the problem. Setting the `CONSOLE_LEVEL=debug` environment variable will now print additional information about the scheduler when you interrupt it, including a backtrace of the current tasks.
0 commit comments