Skip to content

Commit 3a2ff77

Browse files
Restore missing example for Async::PriorityQueue.
1 parent 4adb33e commit 3a2ff77

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

releases.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,35 @@
1010
The new `Async::PriorityQueue` provides a thread-safe, fiber-aware queue where consumers can specify priority levels. Higher priority consumers are served first when items become available, with FIFO ordering maintained for equal priorities. This is useful for implementing priority-based task processing systems where critical operations need to be handled before lower priority work.
1111

1212
```ruby
13-
rubo
13+
require 'async'
14+
require 'async/priority_queue'
15+
16+
Async do
17+
queue = Async::PriorityQueue.new
18+
19+
# Start consumers with different priorities
20+
low_priority = async do
21+
puts "Low priority consumer got: #{queue.dequeue(priority: 1)}"
22+
end
23+
24+
medium_priority = async do
25+
puts "Medium priority consumer got: #{queue.dequeue(priority: 5)}"
26+
end
27+
28+
high_priority = async do
29+
puts "High priority consumer got: #{queue.dequeue(priority: 10)}"
30+
end
31+
32+
# Add items to the queue
33+
queue.push("first item")
34+
queue.push("second item")
35+
queue.push("third item")
36+
37+
# Output:
38+
# High priority consumer got: first item
39+
# Medium priority consumer got: second item
40+
# Low priority consumer got: third item
41+
end
1442
```
1543

1644
## v2.28.1

0 commit comments

Comments
 (0)