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 +4 -4
- data/lib/async/barrier.rb +21 -3
- data/lib/async/condition.rb +0 -1
- data/lib/async/queue.rb +3 -1
- data/lib/async/variable.rb +55 -0
- data/lib/async/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 505786d92573cb06d44ba76fdf587c1a8d5ac1eab7e373fbb5380f85ada6686e
|
4
|
+
data.tar.gz: bc935c07dcbe370ff7379971e670548be2133891e3f4ba703e434e109d691283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
53
|
+
# Wait for all tasks.
|
54
|
+
# @asynchronous Will wait for tasks to finish executing.
|
54
55
|
def wait
|
55
|
-
|
56
|
-
|
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
|
data/lib/async/condition.rb
CHANGED
data/lib/async/queue.rb
CHANGED
@@ -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
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.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:
|
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.
|
183
|
+
rubygems_version: 3.1.6
|
183
184
|
signing_key:
|
184
185
|
specification_version: 4
|
185
186
|
summary: A concurrency framework for Ruby.
|