async 1.29.2 → 1.30.2

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: 3613e4f3c3948bdf49fba954cca2f5df7934c52773dc533c424485aebaf800d6
4
- data.tar.gz: ef790cb3bf5bb3bd248cbae57917f8a1598ffb94acef79a024e3d786e663f3ff
3
+ metadata.gz: 505786d92573cb06d44ba76fdf587c1a8d5ac1eab7e373fbb5380f85ada6686e
4
+ data.tar.gz: bc935c07dcbe370ff7379971e670548be2133891e3f4ba703e434e109d691283
5
5
  SHA512:
6
- metadata.gz: 99f619c7c76e7767b49ba8ff67e243a015b7a9f981df347ed4271c4bfafa1a465822293d177d42fd7e2ea184a628579853c233e060522e4a4f388c201a26ae12
7
- data.tar.gz: 28046633dc2f14dae25828666cf611b9bd8d96fdaa140fc66126b4a3b48030d8811fd1081e4c9ecc46288eaa7b5d962a0845e54a81873b47bc9d3407c9f3b0a1
6
+ metadata.gz: 479cb9a9fad1eeae60993051cd91d8698b47f7dc6fd0129b4672bedf8bcb572c0515d91f5a0d4872da3c2f7d72941c316d86b9d9784fcb2744b1c746c8ba7f20
7
+ data.tar.gz: c954400df7d37eb5f85dda0365390eb77205a0e2293a3c43291136bf1abcdc522c7b5171e465fa4d1026e9d704a9a7b30c1a765633d0e4c5249b1973b3e7036e
data/lib/async/barrier.rb CHANGED
@@ -50,11 +50,29 @@ module Async
50
50
  @tasks.empty?
51
51
  end
52
52
 
53
- # Wait for tasks in FIFO order.
53
+ # Wait for all tasks.
54
+ # @asynchronous Will wait for tasks to finish executing.
54
55
  def wait
55
- while task = @tasks.shift
56
- task.wait
56
+ # TODO: This would be better with linked list.
57
+ while @tasks.any?
58
+ task = @tasks.first
59
+
60
+ begin
61
+ task.wait
62
+ ensure
63
+ # We don't know for sure that the exception was due to the task completion.
64
+ unless task.running?
65
+ # Remove the task from the waiting list if it's finished:
66
+ @tasks.shift if @tasks.first == task
67
+ end
68
+ end
57
69
  end
58
70
  end
71
+
72
+ def stop
73
+ # We have to be careful to avoid enumerating tasks while adding/removing to it:
74
+ tasks = @tasks.dup
75
+ tasks.each(&:stop)
76
+ end
59
77
  end
60
78
  end
@@ -21,7 +21,6 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require 'fiber'
24
- require 'forwardable'
25
24
  require_relative 'node'
26
25
 
27
26
  module Async
data/lib/async/queue.rb CHANGED
@@ -48,7 +48,9 @@ module Async
48
48
  self.signal unless self.empty?
49
49
  end
50
50
 
51
- alias << enqueue
51
+ def <<(item)
52
+ enqueue(item)
53
+ end
52
54
 
53
55
  def dequeue
54
56
  while @items.empty?
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2017, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'condition'
24
+
25
+ module Async
26
+ class Variable
27
+ def initialize(condition = Condition.new)
28
+ @condition = condition
29
+ @value = nil
30
+ end
31
+
32
+ def resolve(value = true)
33
+ @value = value
34
+ condition = @condition
35
+ @condition = nil
36
+
37
+ self.freeze
38
+
39
+ condition.signal(value)
40
+ end
41
+
42
+ def resolved?
43
+ @condition.nil?
44
+ end
45
+
46
+ def value
47
+ @condition&.wait
48
+ return @value
49
+ end
50
+
51
+ def wait
52
+ self.value
53
+ end
54
+ end
55
+ end
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.29.2"
24
+ VERSION = "1.30.2"
25
25
  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.29.2
4
+ version: 1.30.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2022-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -156,6 +156,7 @@ files:
156
156
  - lib/async/scheduler.rb
157
157
  - lib/async/semaphore.rb
158
158
  - lib/async/task.rb
159
+ - lib/async/variable.rb
159
160
  - lib/async/version.rb
160
161
  - lib/async/wrapper.rb
161
162
  - lib/kernel/async.rb
@@ -179,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
180
  - !ruby/object:Gem::Version
180
181
  version: '0'
181
182
  requirements: []
182
- rubygems_version: 3.2.22
183
+ rubygems_version: 3.1.6
183
184
  signing_key:
184
185
  specification_version: 4
185
186
  summary: A concurrency framework for Ruby.