async-tools 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2f7193e8f54757e2be76b09a18572b5cde969b091516b9826ee3bdab71eaeb42
4
- data.tar.gz: 81603e9b6548ea47dd29479bd777ac062b0d302ea33cfcaa24a2fd7112f63a84
3
+ metadata.gz: 076d4f7b65287933136f3f2f05417e77dcd548bbe1eb9bfb475eff44b6003891
4
+ data.tar.gz: 18c1b63f416d4890b7696a3a3ba94de0e8cb0df7ccb6e115fe328127f7f93e9d
5
5
  SHA512:
6
- metadata.gz: 8dbb45e454ed0670326c4a75053ff5a582fddf8b251f292a31ad1f31c2823373ae78d6ed4770920d4aae2fed25a049165e86631f54cb7176a34053f512b7f87f
7
- data.tar.gz: fff7406a7e35645c548efd356d1fd14a5271bb57a4d36fcf51d0d6ab764d9ff2acb717f4b1c161a53788acb218569f4c7fc437181378b1a72b33ed900ab6d490
6
+ metadata.gz: 4a32fb5123b0d520ffd436e07b2003b116f9e3883b386048bb24e4b1327fbcb8de593573a8b00170859c0fef6c18f880ad79d7d78d77dd0446355d55c9ec2545
7
+ data.tar.gz: 918a7bfb836f8a4725dc2b7869aaa4879a74918267cfb7c9cf07a9d73a218a626bed0d75f83373dd008ad59ebce7273949364ac27471cda4ab8e395cd1c678e9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- async-tools (0.1.5)
4
+ async-tools (0.1.7)
5
5
  async (~> 2.3)
6
6
  zeitwerk (~> 2.6)
7
7
 
data/lib/async/bus/bus.rb CHANGED
@@ -5,9 +5,11 @@ class Async::Bus::Bus
5
5
 
6
6
  include Console
7
7
 
8
- def initialize(name: :default, limit: 10)
8
+ def initialize(name: :default, limit: 10, parent: Async::Task.current)
9
9
  @name = name
10
10
  @limit = limit
11
+ @parent = parent
12
+
11
13
  @closed = false
12
14
 
13
15
  @subscribers = Hash.new { |hash, key| hash[key] = [] }
@@ -43,7 +45,7 @@ class Async::Bus::Bus
43
45
  serve(chan, event_name, callable)
44
46
  end
45
47
 
46
- def async_subscribe(*, **, &) = Async { subscribe(*, **, &) }
48
+ def async_subscribe(*, **, &) = @parent.async { subscribe(*, **, &) }
47
49
  def on_event(&block) = @on_event_callback = block
48
50
 
49
51
  def close
data/lib/async/channel.rb CHANGED
@@ -77,7 +77,7 @@ class Async::Channel
77
77
  @subscribers -= 1
78
78
  end
79
79
 
80
- def async(parent: (@parent || Task.current), &block)
80
+ def async(parent: (@parent || Async::Task.current), &block)
81
81
  each do |item|
82
82
  parent.async(item, &block)
83
83
  end
data/lib/async/timer.rb CHANGED
@@ -7,20 +7,21 @@ class Async::Timer
7
7
 
8
8
  class AlreadyStarted < Error; end
9
9
 
10
- def initialize(delay, repeat: true, start: true, run_on_start: false, parent: Async::Task.current, &block)
11
- raise ArgumentError, "Block must be given" if block.nil?
10
+ def initialize(delay, repeat: true, start: true, run_on_start: false, parent: Async::Task.current, call: nil, &block) # rubocop:disable Metrics/ParameterLists
11
+ callables = [call, block]
12
+ raise ArgumentError, "either block or call: must be given" if callables.all?(&:nil?) || callables.none?(&:nil?)
12
13
 
13
14
  @delay = delay
14
15
  @repeat = repeat
15
16
  @run_on_start = run_on_start
16
17
  @parent = parent
17
- @block = block
18
+ @callable = call || block
18
19
 
19
20
  self.start if start
20
21
  end
21
22
 
22
23
  def stop = @task.stop
23
- def call = @block.call
24
+ def call = @callable.call
24
25
 
25
26
  def active? = @active
26
27
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Async # rubocop:disable Style/ClassAndModuleChildren
4
4
  module Tools
5
- VERSION = "0.1.5"
5
+ VERSION = "0.1.7"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gleb Sinyavskiy