ztimer 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/lib/ztimer.rb +11 -1
- data/lib/ztimer/slot.rb +13 -2
- data/lib/ztimer/version.rb +1 -1
- data/lib/ztimer/watcher.rb +7 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f141e0e904b09ba4e9479dfaa3a0ec47ed48ee3
|
4
|
+
data.tar.gz: 6c3ecec2bac2dd388b4eee8154187f14836cae22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc01e57fc11a70e3927f5643f0c639654d75c6f1bcea8aa6a56ca3f185a22476177430e1cc3098020c129900b8b516c3760aebf52edbaf57b8e72149139abf66
|
7
|
+
data.tar.gz: 017113396491866580b63ae0242ffbe2085427b1c55e2c45dfc0a5233f11b5f08e015c0e0006a931b39ac49536e564d72018ef148ca3594a78c37c7181f3521f
|
data/README.md
CHANGED
@@ -27,10 +27,19 @@ is illustrated below:
|
|
27
27
|
```ruby
|
28
28
|
require 'ztimer'
|
29
29
|
|
30
|
-
delay =
|
30
|
+
delay = 1000 # milliseconds
|
31
31
|
Ztimer.after(delay) do
|
32
32
|
puts "Doing something useful..."
|
33
33
|
end
|
34
|
+
|
35
|
+
# Recurrent jobs
|
36
|
+
job = Ztimer.every(delay) do # execute the block every second
|
37
|
+
puts "Executing a recurrent job..."
|
38
|
+
end
|
39
|
+
|
40
|
+
sleep 10 # wait for 10 seconds (10 executions)
|
41
|
+
job.cancel! # cancel the recurrent job
|
42
|
+
|
34
43
|
```
|
35
44
|
|
36
45
|
By default **Ztimer** will run at maximum 20 notifications concurrently, so that if you have 100 notifications to be
|
data/lib/ztimer.rb
CHANGED
@@ -22,7 +22,17 @@ module Ztimer
|
|
22
22
|
def after(milliseconds, &callback)
|
23
23
|
enqueued_at = @metric.utc_microseconds
|
24
24
|
expires_at = enqueued_at + milliseconds * 1000
|
25
|
-
slot = Slot.new(enqueued_at, expires_at, &callback)
|
25
|
+
slot = Slot.new(enqueued_at, expires_at, -1, &callback)
|
26
|
+
|
27
|
+
add(slot)
|
28
|
+
|
29
|
+
return slot
|
30
|
+
end
|
31
|
+
|
32
|
+
def every(milliseconds, &callback)
|
33
|
+
enqueued_at = @metric.utc_microseconds
|
34
|
+
expires_at = enqueued_at + milliseconds * 1000
|
35
|
+
slot = Slot.new(enqueued_at, expires_at, milliseconds * 1000, &callback)
|
26
36
|
|
27
37
|
add(slot)
|
28
38
|
|
data/lib/ztimer/slot.rb
CHANGED
@@ -1,18 +1,29 @@
|
|
1
1
|
|
2
2
|
module Ztimer
|
3
3
|
class Slot
|
4
|
-
attr_reader :enqueued_at, :expires_at, :callback
|
4
|
+
attr_reader :enqueued_at, :expires_at, :recurrency, :callback
|
5
5
|
attr_accessor :started_at, :executed_at
|
6
6
|
|
7
|
-
def initialize(enqueued_at, expires_at, &callback)
|
7
|
+
def initialize(enqueued_at, expires_at,recurrency = -1, &callback)
|
8
8
|
@enqueued_at = enqueued_at
|
9
9
|
@expires_at = expires_at
|
10
|
+
@recurrency = recurrency
|
10
11
|
@callback = callback
|
11
12
|
@started_at = nil
|
12
13
|
@executed_at = nil
|
13
14
|
@canceled = false
|
14
15
|
end
|
15
16
|
|
17
|
+
def recurrent?
|
18
|
+
return @recurrency > 0
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset!
|
22
|
+
if recurrent?
|
23
|
+
@expires_at += recurrency
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
16
27
|
def canceled?
|
17
28
|
return @canceled
|
18
29
|
end
|
data/lib/ztimer/version.rb
CHANGED
data/lib/ztimer/watcher.rb
CHANGED
@@ -66,7 +66,13 @@ module Ztimer
|
|
66
66
|
if slot && (slot.expires_at < @metric.utc_microseconds)
|
67
67
|
@slots.shift
|
68
68
|
slot.started_at = @metric.utc_microseconds
|
69
|
-
|
69
|
+
unless slot.canceled?
|
70
|
+
execute(slot)
|
71
|
+
if slot.recurrent?
|
72
|
+
slot.reset!
|
73
|
+
@slots << slot
|
74
|
+
end
|
75
|
+
end
|
70
76
|
else
|
71
77
|
slot = nil
|
72
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ztimer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Groza Sergiu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-03-
|
11
|
+
date: 2016-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -123,9 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.4.
|
126
|
+
rubygems_version: 2.4.8
|
127
127
|
signing_key:
|
128
128
|
specification_version: 4
|
129
129
|
summary: An asyncrhonous timer
|
130
130
|
test_files: []
|
131
|
-
has_rdoc:
|