async-background 0.2.5 → 0.2.6

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: b412d31294adfc8d7a2586f31f42f47cd0a004e992016615dff81fc1828b7e90
4
- data.tar.gz: 3d629e5272bd5f819e8fe2f3ed4507e73b720ce13c71c06433f1d7f3f9e9f563
3
+ metadata.gz: 6668497aee969150ccc5e31b7c9ec57a47c2b107aa337686393262ee2b78f429
4
+ data.tar.gz: 3cbf76732b4987bfa5d7c9257b529c716e0adfec11e7d02f6a4105b5c5ce54e1
5
5
  SHA512:
6
- metadata.gz: 9eab99f4c978281eea0689a96dfc45b356e82991fc177bf57ab919f688c397d6361f348fc0451c20b45207c124f15106e9b4bd6e637866103830fd64937266a0
7
- data.tar.gz: 15b3e8677ec777ae4395d87fbfca81ce9b79fa67d3e2c1b425cbcdac17c12df5f382550a13593f1d71518e0f6ead48e31dd5e474c99634aedc7bea6fa4afe9ba
6
+ metadata.gz: 5f75ed0c52dda7d988fbf73fa701c00f3c6ff3b869cd36d6566593c9a8095134721a011ada08c337206d64348f919ca807c77e07dd43c4c14f31c637f58769d4
7
+ data.tar.gz: 0b00eb1e333173929e788103042dcd2c3be4696da0acad65a2f5d6bc0bdc6e5bbeeccf0353ad27af7281d0d62aaf3342c1c9d1f8ce8594caee18dc28435e645a
@@ -21,6 +21,11 @@ module Async
21
21
  entry
22
22
  end
23
23
 
24
+ def replace_top(entry)
25
+ @data[0] = entry
26
+ sift_down(0)
27
+ end
28
+
24
29
  def peek
25
30
  @data.first
26
31
  end
@@ -30,6 +30,7 @@ module Async
30
30
  def run
31
31
  Async do |task|
32
32
  setup_signal_handlers
33
+ start_signal_watcher(task)
33
34
 
34
35
  loop do
35
36
  entry = heap.peek
@@ -41,11 +42,9 @@ module Async
41
42
  break unless running?
42
43
 
43
44
  now = monotonic_now
44
- while (top = heap.peek) && top.next_run_at <= now
45
+ while (entry = heap.peek) && entry.next_run_at <= now
45
46
  break unless running?
46
47
 
47
- entry = heap.pop
48
-
49
48
  if entry.running
50
49
  logger.warn('Async::Background') { "#{entry.name}: skipped, previous run still active" }
51
50
  else
@@ -58,7 +57,7 @@ module Async
58
57
  end
59
58
 
60
59
  entry.reschedule(monotonic_now)
61
- heap.push(entry)
60
+ heap.replace_top(entry)
62
61
  end
63
62
  end
64
63
 
@@ -91,21 +90,20 @@ module Async
91
90
  end
92
91
  end
93
92
 
94
- def wait_with_shutdown(task, duration)
95
- timer = task.async(transient: true) do
96
- task.sleep duration
97
- shutdown.signal
98
- end
99
-
100
- watcher = task.async(transient: true) do
101
- @signal_r.wait_readable
102
- @signal_r.read_nonblock(256) rescue nil
103
- shutdown.signal
93
+ def start_signal_watcher(task)
94
+ task.async(transient: true) do
95
+ loop do
96
+ @signal_r.wait_readable
97
+ @signal_r.read_nonblock(256) rescue nil
98
+ shutdown.signal
99
+ break unless running?
100
+ end
104
101
  end
102
+ end
105
103
 
106
- shutdown.wait
107
- timer.stop
108
- watcher.stop
104
+ def wait_with_shutdown(task, duration)
105
+ task.with_timeout(duration) { shutdown.wait }
106
+ rescue ::Async::TimeoutError
109
107
  end
110
108
 
111
109
  def build_heap(config_path)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Async
4
4
  module Background
5
- VERSION = '0.2.5'
5
+ VERSION = '0.2.6'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-background
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roman Hajdarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-20 00:00:00.000000000 Z
11
+ date: 2026-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.4.22
120
+ rubygems_version: 3.3.27
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Lightweight heap-based cron/interval scheduler for Async.