async 1.28.9 → 1.29.0

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: 6ca8ba4c610a65bfe25595780c26681ad5920a5423b8f065d12917df8db4144d
4
- data.tar.gz: d5488881518a83750bf540a150e66dd63d993a88c30d5e6f839714456cd2709e
3
+ metadata.gz: 421b9e871d367ee3c769c4f7a9f3e51125d5e11c45d37f9d8c562a33ecce70ed
4
+ data.tar.gz: 868be7ef14d83fb04620c862d69b38e03f0b5ba036cd2d65e6caf0f45c58a689
5
5
  SHA512:
6
- metadata.gz: 33200c36d76c0af962c8573da82962e1c32d83c74c3c98486b401ba366d2417d85afb6f7e70432bb4e667c9047a0d074afc308436b8f6c50af452f2269a4d6aa
7
- data.tar.gz: be364fa61facbaeb3879945cd137499da161646cee5ceb4da31db12173f9b6fea4bbf8754b5aa076959e8b2a59778ba929724781aa32da18b01ce44c334e1ad4
6
+ metadata.gz: 47620eaf32dc53e1978f3c07ef66823c6aa4b3e85ec23ac3a207d1cdb39a06c790428a9b67dc3b955b74edf723faa567b2f8a077893ecf0c3d1383c5c62997e0
7
+ data.tar.gz: 74e3b0e17cc0d8f63bdc2c7e4aa40033062a07d2a5a1866f3ca3ac072376264463f8b11203485a07bbed11c475cbad6a2ac81f9297e900a732263f8b7b0b401b
@@ -20,25 +20,23 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require 'delegate'
24
+
23
25
  module Async
24
26
  module Debug
25
- class Monitor
27
+ class Monitor < Delegator
26
28
  def initialize(monitor, selector)
27
29
  @monitor = monitor
28
30
  @selector = selector
29
31
  end
30
32
 
31
- def close
32
- @selector.deregister(@monitor.io)
33
- @monitor.close
33
+ def __getobj__
34
+ @monitor
34
35
  end
35
36
 
36
- def method_missing(*arguments, &block)
37
- @monitor.send(*arguments)
38
- end
39
-
40
- def respond_to?(*arguments)
41
- @monitor.respond_to?(*arguments)
37
+ def close
38
+ @selector.deregister(self)
39
+ @monitor.close
42
40
  end
43
41
 
44
42
  def inspect
@@ -24,6 +24,7 @@ require_relative 'monitor'
24
24
  require_relative '../logger'
25
25
 
26
26
  require 'nio'
27
+ require 'set'
27
28
 
28
29
  module Async
29
30
  module Debug
@@ -36,7 +37,7 @@ module Async
36
37
  class Selector
37
38
  def initialize(selector = NIO::Selector.new)
38
39
  @selector = selector
39
- @monitors = {}
40
+ @monitors = Set.new
40
41
  end
41
42
 
42
43
  def register(object, interests)
@@ -46,26 +47,18 @@ module Async
46
47
  raise RuntimeError, "Could not convert #{io} into IO!"
47
48
  end
48
49
 
49
- if monitor = @monitors[io.fileno]
50
- raise RuntimeError, "Trying to register monitor for #{object.inspect} but it was already registered: #{monitor.inspect}!"
51
- end
52
-
53
50
  monitor = Monitor.new(@selector.register(object, interests), self)
54
51
 
55
- @monitors[io.fileno] = monitor
52
+ @monitors.add(monitor)
56
53
 
57
54
  return monitor
58
55
  end
59
56
 
60
- def deregister(object)
61
- Async.logger.debug(self) {"Deregistering #{object.inspect}."}
62
-
63
- unless io = ::IO.try_convert(object)
64
- raise RuntimeError, "Could not convert #{io} into IO!"
65
- end
57
+ def deregister(monitor)
58
+ Async.logger.debug(self) {"Deregistering #{monitor.inspect}."}
66
59
 
67
- unless @monitors.delete(io.fileno)
68
- raise RuntimeError, "Trying to remove monitor for #{io.inspect} but it was not registered!"
60
+ unless @monitors.delete?(monitor)
61
+ raise RuntimeError, "Trying to remove monitor for #{monitor.inspect} but it was not registered!"
69
62
  end
70
63
  end
71
64
 
@@ -75,7 +68,7 @@ module Async
75
68
 
76
69
  def close
77
70
  if @monitors.any?
78
- raise LeakError, @monitors.values
71
+ raise LeakError, @monitors
79
72
  end
80
73
  ensure
81
74
  @selector.close
data/lib/async/reactor.rb CHANGED
@@ -47,9 +47,7 @@ module Async
47
47
  # running.
48
48
  def self.run(*arguments, **options, &block)
49
49
  if current = Task.current?
50
- reactor = current.reactor
51
-
52
- return reactor.async(*arguments, **options, &block)
50
+ return current.async(*arguments, **options, &block)
53
51
  else
54
52
  reactor = self.new
55
53
 
@@ -96,6 +94,7 @@ module Async
96
94
  end
97
95
 
98
96
  attr :scheduler
97
+ attr :logger
99
98
 
100
99
  # @reentrant Not thread safe.
101
100
  def block(blocker, timeout)
@@ -135,10 +134,6 @@ module Async
135
134
  end
136
135
  end
137
136
 
138
- def logger
139
- @logger || Console.logger
140
- end
141
-
142
137
  def to_s
143
138
  "\#<#{self.description} #{@children&.size || 0} children (#{stopped? ? 'stopped' : 'running'})>"
144
139
  end
@@ -167,7 +162,7 @@ module Async
167
162
  # - Avoid scheduler overhead if no blocking operation is performed.
168
163
  task.run(*arguments)
169
164
 
170
- # logger.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..."
165
+ # Console.logger.debug "Initial execution of task #{fiber} complete (#{result} -> #{fiber.alive?})..."
171
166
  return task
172
167
  end
173
168
 
@@ -210,7 +205,7 @@ module Async
210
205
  # @param timeout [Float | nil] the maximum timeout, or if nil, indefinite.
211
206
  # @return [Boolean] whether there is more work to do.
212
207
  def run_once(timeout = nil)
213
- # logger.debug(self) {"@ready = #{@ready} @running = #{@running}"}
208
+ # Console.logger.debug(self) {"@ready = #{@ready} @running = #{@running}"}
214
209
 
215
210
  if @ready.any?
216
211
  # running used to correctly answer on `finished?`, and to reuse Array object.
@@ -258,7 +253,7 @@ module Async
258
253
  interval = timeout
259
254
  end
260
255
 
261
- # logger.info(self) {"Selecting with #{@children&.size} children with interval = #{interval ? interval.round(2) : 'infinite'}..."}
256
+ # Console.logger.info(self) {"Selecting with #{@children&.size} children with interval = #{interval ? interval.round(2) : 'infinite'}..."}
262
257
  if monitors = @selector.select(interval)
263
258
  monitors.each do |monitor|
264
259
  monitor.value.resume
@@ -295,7 +290,7 @@ module Async
295
290
  return initial_task
296
291
  ensure
297
292
  @scheduler&.clear!
298
- logger.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."}
293
+ Console.logger.debug(self) {"Exiting run-loop because #{$! ? $! : 'finished'}."}
299
294
  end
300
295
 
301
296
  def stop(later = true)
data/lib/async/task.rb CHANGED
@@ -81,11 +81,13 @@ module Async
81
81
  @result = nil
82
82
  @finished = finished
83
83
 
84
- @logger = logger
84
+ @logger = logger || @parent.logger
85
85
 
86
86
  @fiber = make_fiber(&block)
87
87
  end
88
88
 
89
+ attr :logger
90
+
89
91
  if Fiber.current.respond_to?(:backtrace)
90
92
  def backtrace(*arguments)
91
93
  @fiber&.backtrace(*arguments)
@@ -96,10 +98,6 @@ module Async
96
98
  "\#<#{self.description} (#{@status})>"
97
99
  end
98
100
 
99
- def logger
100
- @logger || Console.logger
101
- end
102
-
103
101
  # @attr ios [Reactor] The reactor the task was created within.
104
102
  attr :reactor
105
103
 
@@ -242,9 +240,9 @@ module Async
242
240
  raise
243
241
  elsif @finished.nil?
244
242
  # If no one has called wait, we log this as an error:
245
- logger.error(self) {$!}
243
+ Console.logger.error(self) {$!}
246
244
  else
247
- logger.debug(self) {$!}
245
+ Console.logger.debug(self) {$!}
248
246
  end
249
247
  end
250
248
 
@@ -264,7 +262,7 @@ module Async
264
262
  begin
265
263
  @result = yield(self, *arguments)
266
264
  @status = :complete
267
- # logger.debug(self) {"Task was completed with #{@children.size} children!"}
265
+ # Console.logger.debug(self) {"Task was completed with #{@children.size} children!"}
268
266
  rescue Stop
269
267
  stop!
270
268
  rescue StandardError => error
@@ -272,7 +270,7 @@ module Async
272
270
  rescue Exception => exception
273
271
  fail!(exception, true)
274
272
  ensure
275
- # logger.debug(self) {"Task ensure $!=#{$!} with #{@children.size} children!"}
273
+ # Console.logger.debug(self) {"Task ensure $!=#{$!} with #{@children.size} children!"}
276
274
  finish!
277
275
  end
278
276
  end
data/lib/async/version.rb CHANGED
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module Async
24
- VERSION = "1.28.9"
24
+ VERSION = "1.29.0"
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.28.9
4
+ version: 1.29.0
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-02-16 00:00:00.000000000 Z
11
+ date: 2021-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: console