delayer 1.1.0 → 1.1.1

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: b2630bd1444004b5d79a42afc7e6c0a456eaa615c2d98ff7403f36a035951c9d
4
- data.tar.gz: 97a1594619a9352dee6298fb4a13d0684b8e75b2cd2e0fa973dac3ae8641ee11
3
+ metadata.gz: a2b9095d6ff8a3d46813d7ca787b7ffcf13050de5a21de2ba8b63940a9394631
4
+ data.tar.gz: 1da28faf0ed99c6f87450c85c469b967ca2cdc5dc08e5bcbb629d050f1d5aa66
5
5
  SHA512:
6
- metadata.gz: e96977c14039b5dcae415c6525a9e8839b13de2922b495a402f3678046be8f0e29cc9ad59cf122210afa5fbc67a1422a90c773c839ecd062e380821f70ef36cc
7
- data.tar.gz: d625b3e90a7288a3dac9e8d020e99e1ab7f707bcdbee9298ff3674c4f25ab56a4d45c91a9348d6bac1df632bfd50b39734e57ab92a670a3c44eccfd1bd52b936
6
+ metadata.gz: 22cac588a6463302883fbac1ada84b6922cf84076f854c2e75757ea495ac71569b133a0955dc131ca582d08b3b175beca6fb184e778975eda172ff5846747d7b
7
+ data.tar.gz: fc1cf72aae866f8d832f9f856b44dc7dd2e29e26459715800ba4d30ce8a503e782e89e86e302b0629b73f55049a083eeba60030466290f6fef376bb38f1f78b8
@@ -9,9 +9,15 @@ module Delayer
9
9
  def initialize(delayer, delay:, &proc)
10
10
  @delayer = delayer
11
11
  @proc = proc
12
- @reserve_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + delay
12
+ case delay
13
+ when Time
14
+ @reserve_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + delay.to_f - Time.now.to_f
15
+ else
16
+ @reserve_at = Process.clock_gettime(Process::CLOCK_MONOTONIC) + delay.to_f
17
+ end
13
18
  @left = @right = @cancel = nil
14
19
  @size = 1
20
+ @procedure = nil
15
21
  @delayer.class.reserve(self)
16
22
  end
17
23
 
@@ -26,7 +26,7 @@ module Delayer
26
26
  @procedure = Procedure.new(self, &proc)
27
27
  else
28
28
  @procedure = DelayedProcedure.new(self, delay: delay, &proc)
29
- end
29
+ end
30
30
  end
31
31
 
32
32
  # Cancel this job
@@ -52,6 +52,7 @@ module Delayer
52
52
  @remain_received = false
53
53
  @lock = Mutex.new
54
54
  @bucket = Bucket.new(nil, nil, {}, nil)
55
+ @reserve = nil
55
56
  end
56
57
  end
57
58
 
@@ -163,7 +164,6 @@ module Delayer
163
164
  # ==== Return
164
165
  # self
165
166
  def reserve(procedure)
166
- priority = procedure.delayer.priority
167
167
  lock.synchronize do
168
168
  if @reserve
169
169
  @reserve = @reserve.add(procedure)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Delayer
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
@@ -373,6 +373,16 @@ class TestDelayer < Test::Unit::TestCase
373
373
  assert_equal([1, 2, 0, 3], a)
374
374
  end
375
375
 
376
+ def test_timer_give_time
377
+ delayer = Delayer.generate_class expire: 0.01
378
+ a = []
379
+ delayer.new(delay: Time.new) { a << 0 }
380
+
381
+ delayer.run
382
+
383
+ assert_equal([0], a)
384
+ end
385
+
376
386
  def test_plural_timer
377
387
  delayer = Delayer.generate_class expire: 0.01
378
388
  a = []
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delayer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toshiaki Asai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-01 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.0.6
101
+ rubygems_version: 3.1.2
102
102
  signing_key:
103
103
  specification_version: 4
104
104
  summary: Delay the processing