async 1.28.1 → 1.28.6

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: 1e4e0ec2acca1af0f271efcedc344b762e5f3f16624aea68798b4bb6cd049b73
4
- data.tar.gz: ed8c76d71768170aada8b9f4d7953f67731e18da317a3429b2668b8ef7183d29
3
+ metadata.gz: 6f37f30a9b3c4eecb9dd393813bd30545b4c9e07529be6fda43f50c63c35bc53
4
+ data.tar.gz: 12e98fb9b1758199fd7e06a1ae4ac1e6b696844ceb42f75827905bd216a2b9fa
5
5
  SHA512:
6
- metadata.gz: 902e77b03639f8a68f05df761a7f6cd75869e4abc25e9835b5e412301e6ab67e5fb9c4da4c99bedbaeb30e01fe84cf9bbfb062971f20fc0437c5f69edf21190f
7
- data.tar.gz: 1810f96d715b91c18e6dfbdb08d3d2da7531c3b8d562bb750b05ef850f88e632709559b710af7efb8354e0d2784b242c94d306d7db64940a7ef147c79c26cf73
6
+ metadata.gz: bf2e4696aae38b3c9e61ea1cba7c9eb115bab9646eae5e68459cc6f82a4b9e34010a6bd111f5983c2e902dd1f8db2ffafae56d3b520698d923cabf539ed35f39
7
+ data.tar.gz: c71f02fa817c1d21dbefe64ade8aea5cbdfc410550c46aee478fa36a040e099a6ac137d59c32f591acc1d3aed67c23bf6b0e0e89d7f0a84fbadc9c10710fdd54
data/lib/async/queue.rb CHANGED
@@ -34,6 +34,10 @@ module Async
34
34
 
35
35
  attr :items
36
36
 
37
+ def size
38
+ @items.size
39
+ end
40
+
37
41
  def empty?
38
42
  @items.empty?
39
43
  end
data/lib/async/reactor.rb CHANGED
@@ -102,7 +102,7 @@ module Async
102
102
  fiber = Fiber.current
103
103
 
104
104
  if timeout
105
- timer = self.after(timeout) do
105
+ timer = @timers.after(timeout) do
106
106
  if fiber.alive?
107
107
  fiber.resume(false)
108
108
  end
@@ -223,7 +223,7 @@ module Async
223
223
  @running.clear
224
224
  end
225
225
 
226
- unless @blocked.zero?
226
+ if @unblocked.any?
227
227
  unblocked = Array.new
228
228
 
229
229
  @guard.synchronize do
@@ -34,24 +34,20 @@ module Async
34
34
 
35
35
  def initialize(reactor)
36
36
  @reactor = reactor
37
- @wrappers = nil
38
37
  end
39
38
 
39
+ attr :wrappers
40
+
40
41
  def set!
41
- @wrappers = {}
42
42
  Fiber.set_scheduler(self)
43
43
  end
44
44
 
45
45
  def clear!
46
- # Because these instances are created with `autoclose: false`, this does not close the underlying file descriptor:
47
- # @ios&.each_value(&:close)
48
-
49
- @wrappers = nil
50
46
  Fiber.set_scheduler(nil)
51
47
  end
52
48
 
53
49
  private def from_io(io)
54
- @wrappers[io] ||= Wrapper.new(io, @reactor)
50
+ Wrapper.new(io, @reactor)
55
51
  end
56
52
 
57
53
  def io_wait(io, events, timeout = nil)
@@ -82,12 +78,12 @@ module Async
82
78
  # @returns [Process::Status] A process status instance.
83
79
  def process_wait(pid, flags)
84
80
  Thread.new do
85
- Process::Status.wait(pid, flags)
81
+ ::Process::Status.wait(pid, flags)
86
82
  end.value
87
83
  end
88
84
 
89
85
  def kernel_sleep(duration)
90
- @reactor.sleep(duration)
86
+ self.block(nil, duration)
91
87
  end
92
88
 
93
89
  def block(blocker, timeout)
@@ -102,11 +98,13 @@ module Async
102
98
  end
103
99
 
104
100
  def fiber(&block)
105
- task = Task.new(&block)
101
+ task = Task.new(@reactor, &block)
102
+
103
+ fiber = task.fiber
106
104
 
107
- task.resume
105
+ task.run
108
106
 
109
- return task.fiber
107
+ return fiber
110
108
  end
111
109
  end
112
110
  end
data/lib/async/task.rb CHANGED
@@ -72,14 +72,14 @@ module Async
72
72
  # Create a new task.
73
73
  # @param reactor [Async::Reactor] the reactor this task will run within.
74
74
  # @param parent [Async::Task] the parent task.
75
- def initialize(reactor, parent = Task.current?, logger: nil, **options, &block)
75
+ def initialize(reactor, parent = Task.current?, logger: nil, finished: nil, **options, &block)
76
76
  super(parent || reactor, **options)
77
77
 
78
78
  @reactor = reactor
79
79
 
80
80
  @status = :initialized
81
81
  @result = nil
82
- @finished = nil
82
+ @finished = finished
83
83
 
84
84
  @logger = logger
85
85
 
@@ -88,7 +88,7 @@ module Async
88
88
 
89
89
  if Fiber.current.respond_to?(:backtrace)
90
90
  def backtrace(*arguments)
91
- @fiber.backtrace(*arguments)
91
+ @fiber&.backtrace(*arguments)
92
92
  end
93
93
  end
94
94
 
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.28.1"
24
+ VERSION = "1.28.6"
25
25
  end
data/lib/kernel/sync.rb CHANGED
@@ -28,7 +28,10 @@ module Kernel
28
28
  if task = ::Async::Task.current?
29
29
  yield task
30
30
  else
31
- ::Async::Reactor.run(&block).wait
31
+ ::Async::Reactor.run(
32
+ finished: ::Async::Condition.new,
33
+ &block
34
+ ).wait
32
35
  end
33
36
  end
34
37
  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.28.1
4
+ version: 1.28.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-25 00:00:00.000000000 Z
11
+ date: 2021-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console
@@ -179,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.1.2
182
+ rubygems_version: 3.2.3
183
183
  signing_key:
184
184
  specification_version: 4
185
185
  summary: A concurrency framework for Ruby.