async 1.30.2 → 1.31.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/queue.rb +20 -5
- data/lib/async/semaphore.rb +19 -0
- data/lib/async/task.rb +10 -9
- data/lib/async/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f54f8b2dedcd29cf6a5d5c19b9b6ef11762cac77156439930b29d414e45bb6d4
|
4
|
+
data.tar.gz: c420baf542fe9992737ac9d8594cd3f88bb7764904113d801aa891ec328558ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff4f467f2d8f2bde924e29636d8d0689509acfd1d463825173d03aa75b4235847db43c7fc6a9d4a10e18a444d542332218e1f3a9a0bb471d1a918bb411dd7a73
|
7
|
+
data.tar.gz: 95affc48630a0b2e83457e58024dfa89c091060b1047151849e30bce3a493a5e5ffaa06e824086df347dfb862f66cf834a08f3609d4b718eb7e3c74157bc1ad9
|
data/lib/async/queue.rb
CHANGED
@@ -42,14 +42,16 @@ module Async
|
|
42
42
|
@items.empty?
|
43
43
|
end
|
44
44
|
|
45
|
-
def
|
46
|
-
@items
|
45
|
+
def <<(item)
|
46
|
+
@items << item
|
47
47
|
|
48
48
|
self.signal unless self.empty?
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def enqueue(*items)
|
52
|
+
@items.concat(items)
|
53
|
+
|
54
|
+
self.signal unless self.empty?
|
53
55
|
end
|
54
56
|
|
55
57
|
def dequeue
|
@@ -89,7 +91,7 @@ module Async
|
|
89
91
|
@items.size >= @limit
|
90
92
|
end
|
91
93
|
|
92
|
-
def
|
94
|
+
def <<(item)
|
93
95
|
while limited?
|
94
96
|
@full.wait
|
95
97
|
end
|
@@ -97,6 +99,19 @@ module Async
|
|
97
99
|
super
|
98
100
|
end
|
99
101
|
|
102
|
+
def enqueue *items
|
103
|
+
while !items.empty?
|
104
|
+
while limited?
|
105
|
+
@full.wait
|
106
|
+
end
|
107
|
+
|
108
|
+
available = @limit - @items.size
|
109
|
+
@items.concat(items.shift(available))
|
110
|
+
|
111
|
+
self.signal unless self.empty?
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
100
115
|
def dequeue
|
101
116
|
item = super
|
102
117
|
|
data/lib/async/semaphore.rb
CHANGED
@@ -40,6 +40,25 @@ module Async
|
|
40
40
|
# The tasks waiting on this semaphore.
|
41
41
|
attr :waiting
|
42
42
|
|
43
|
+
# Allow setting the limit. This is useful for cases where the semaphore is used to limit the number of concurrent tasks, but the number of tasks is not known in advance or needs to be modified.
|
44
|
+
#
|
45
|
+
# On increasing the limit, some tasks may be immediately resumed. On decreasing the limit, some tasks may execute until the count is < than the limit.
|
46
|
+
#
|
47
|
+
# @parameter limit [Integer] The new limit.
|
48
|
+
def limit= limit
|
49
|
+
difference = limit - @limit
|
50
|
+
@limit = limit
|
51
|
+
|
52
|
+
# We can't suspend
|
53
|
+
if difference > 0
|
54
|
+
difference.times do
|
55
|
+
break unless fiber = @waiting.shift
|
56
|
+
|
57
|
+
fiber.resume
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
43
62
|
# Is the semaphore currently acquired?
|
44
63
|
def empty?
|
45
64
|
@count.zero?
|
data/lib/async/task.rb
CHANGED
@@ -230,18 +230,19 @@ module Async
|
|
230
230
|
private
|
231
231
|
|
232
232
|
# This is a very tricky aspect of tasks to get right. I've modelled it after `Thread` but it's slightly different in that the exception can propagate back up through the reactor. If the user writes code which raises an exception, that exception should always be visible, i.e. cause a failure. If it's not visible, such code fails silently and can be very difficult to debug.
|
233
|
-
|
234
|
-
def fail!(exception = nil, propagate = true)
|
233
|
+
def fail!(exception = false, propagate = true)
|
235
234
|
@status = :failed
|
236
235
|
@result = exception
|
237
236
|
|
238
|
-
if
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
237
|
+
if exception
|
238
|
+
if propagate
|
239
|
+
raise exception
|
240
|
+
elsif @finished.nil?
|
241
|
+
# If no one has called wait, we log this as a warning:
|
242
|
+
Console.logger.warn(self, "Task may have ended with unhandled exception.", exception)
|
243
|
+
else
|
244
|
+
Console.logger.debug(self, exception)
|
245
|
+
end
|
245
246
|
end
|
246
247
|
end
|
247
248
|
|
data/lib/async/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: console
|
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
- !ruby/object:Gem::Version
|
181
181
|
version: '0'
|
182
182
|
requirements: []
|
183
|
-
rubygems_version: 3.
|
183
|
+
rubygems_version: 3.4.7
|
184
184
|
signing_key:
|
185
185
|
specification_version: 4
|
186
186
|
summary: A concurrency framework for Ruby.
|