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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3722acb6246ee95cecd02b7d763cf695eabe3726510d2eda756ecfe3e809632e
4
- data.tar.gz: da8e9cd294faf48293c39f7577ef6b807d3e46881fb99f248a7d3369bbc2d182
3
+ metadata.gz: b9530ec0131ea1a67aa243eabaaf6a20f2caa1588fe021c5efe4cec58f35c2b4
4
+ data.tar.gz: 51dc5db69d0793b9a1e5feea4de6478a5e63bbafedac307f6e1122c5d29be8bf
5
5
  SHA512:
6
- metadata.gz: b69666de33bf4b97a4b72a9b9e6ecce98651dbc7fc6eab8c124946f979731fdb3b349d3143b6763a5cf2a41b2a2725d8186d3d2903603667dbd5ac973aea7686
7
- data.tar.gz: 3e5a5211537c71bc368aeb7b1d7396693ad6f8908bdbf8e20a5a3baf395a0bb908eddbab2e05f3293667c3e25b2b75d08909df7dc6540d47522f411361ff9628
6
+ metadata.gz: 47b3ac832144d0c6555394368d3089f9577e4000fbb68b71972979d555a22d1028f34895ac7180cbe3a3314f6de7889d90ca6140c6ff27424f0f99e45d6ec085
7
+ data.tar.gz: abc2da19eb893c978826b07cb7ad13c2616b03fd7b559b39742698ae06bbf3558dbe4155db29f14d2bc2ac66812ad8e5bb35c25fe76a338f55ee905dd69c9396
@@ -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
- @waiting << Fiber.current
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?
@@ -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 << Fiber.current
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
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Async
22
- VERSION = "1.15.0"
22
+ VERSION = "1.15.1"
23
23
  end
@@ -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.0
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-21 00:00:00.000000000 Z
11
+ date: 2019-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nio4r