async 1.15.0 → 1.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async/condition.rb +8 -1
- data/lib/async/semaphore.rb +8 -1
- data/lib/async/version.rb +1 -1
- data/spec/async/condition_examples.rb +33 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9530ec0131ea1a67aa243eabaaf6a20f2caa1588fe021c5efe4cec58f35c2b4
|
4
|
+
data.tar.gz: 51dc5db69d0793b9a1e5feea4de6478a5e63bbafedac307f6e1122c5d29be8bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47b3ac832144d0c6555394368d3089f9577e4000fbb68b71972979d555a22d1028f34895ac7180cbe3a3314f6de7889d90ca6140c6ff27424f0f99e45d6ec085
|
7
|
+
data.tar.gz: abc2da19eb893c978826b07cb7ad13c2616b03fd7b559b39742698ae06bbf3558dbe4155db29f14d2bc2ac66812ad8e5bb35c25fe76a338f55ee905dd69c9396
|
data/lib/async/condition.rb
CHANGED
@@ -32,9 +32,16 @@ module Async
|
|
32
32
|
# Queue up the current fiber and wait on yielding the task.
|
33
33
|
# @return [Object]
|
34
34
|
def wait
|
35
|
-
|
35
|
+
fiber = Fiber.current
|
36
36
|
|
37
|
+
@waiting << fiber
|
37
38
|
Task.yield
|
39
|
+
|
40
|
+
# It would be nice if there was a better construct for this. We only need to invoke #delete if the task was not resumed normally. This can only occur with `raise` and `throw`. But there is no easy way to detect this.
|
41
|
+
# ensure when not return or ensure when raise, throw
|
42
|
+
rescue Exception
|
43
|
+
@waiting.delete(fiber)
|
44
|
+
raise
|
38
45
|
end
|
39
46
|
|
40
47
|
# Is any fiber waiting on this notification?
|
data/lib/async/semaphore.rb
CHANGED
@@ -93,10 +93,17 @@ module Async
|
|
93
93
|
|
94
94
|
# Wait until the semaphore becomes available.
|
95
95
|
def wait
|
96
|
+
fiber = Fiber.current
|
97
|
+
|
96
98
|
while blocking?
|
97
|
-
@waiting <<
|
99
|
+
@waiting << fiber
|
98
100
|
Task.yield
|
99
101
|
end
|
102
|
+
|
103
|
+
# ensure when raise, throw
|
104
|
+
rescue Exception
|
105
|
+
@waiting.delete(fiber)
|
106
|
+
raise
|
100
107
|
end
|
101
108
|
end
|
102
109
|
end
|
data/lib/async/version.rb
CHANGED
@@ -50,4 +50,37 @@ RSpec.shared_examples Async::Condition do
|
|
50
50
|
|
51
51
|
subject.signal
|
52
52
|
end
|
53
|
+
|
54
|
+
context "with timeout" do
|
55
|
+
before do
|
56
|
+
@state = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
let!(:task) do
|
60
|
+
reactor.async do |task|
|
61
|
+
task.with_timeout(0.1) do
|
62
|
+
begin
|
63
|
+
@state = :waiting
|
64
|
+
subject.wait
|
65
|
+
@state = :signalled
|
66
|
+
rescue Async::TimeoutError
|
67
|
+
@state = :timeout
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'can timeout while waiting' do
|
74
|
+
task.wait
|
75
|
+
|
76
|
+
expect(@state).to be == :timeout
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'can signal while waiting' do
|
80
|
+
subject.signal
|
81
|
+
task.wait
|
82
|
+
|
83
|
+
expect(@state).to be == :signalled
|
84
|
+
end
|
85
|
+
end
|
53
86
|
end
|
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.15.
|
4
|
+
version: 1.15.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nio4r
|