timers 4.3.0 → 4.3.5

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.
data/lib/timers/wait.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # This file is part of the "timers" project and released under the MIT license.
4
- #
5
- # Copyright, 2018, by Samuel Williams. All rights reserved.
6
- #
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2014-2022, by Samuel Williams.
5
+ # Copyright, 2014-2016, by Tony Arcieri.
6
+ # Copyright, 2015, by Utenmiki.
7
+ # Copyright, 2015, by Donovan Keme.
7
8
 
8
9
  require_relative "interval"
9
10
 
@@ -13,7 +14,7 @@ module Timers
13
14
  def self.for(duration, &block)
14
15
  if duration
15
16
  timeout = new(duration)
16
-
17
+
17
18
  timeout.while_time_remaining(&block)
18
19
  else
19
20
  loop do
@@ -21,31 +22,31 @@ module Timers
21
22
  end
22
23
  end
23
24
  end
24
-
25
+
25
26
  def initialize(duration)
26
27
  @duration = duration
27
28
  @remaining = true
28
29
  end
29
-
30
+
30
31
  attr_reader :duration
31
32
  attr_reader :remaining
32
-
33
+
33
34
  # Yields while time remains for work to be done:
34
35
  def while_time_remaining
35
36
  @interval = Interval.new
36
37
  @interval.start
37
-
38
+
38
39
  yield @remaining while time_remaining?
39
40
  ensure
40
41
  @interval.stop
41
42
  @interval = nil
42
43
  end
43
-
44
+
44
45
  private
45
-
46
+
46
47
  def time_remaining?
47
48
  @remaining = (@duration - @interval.to_f)
48
-
49
+
49
50
  @remaining > 0
50
51
  end
51
52
  end
data/lib/timers.rb CHANGED
@@ -1,11 +1,21 @@
1
1
  # frozen_string_literal: true
2
- #
3
- # This file is part of the "timers" project and released under the MIT license.
4
- #
5
- # Copyright, 2018, by Samuel Williams. All rights reserved.
6
- #
7
2
 
8
- require "timers/version"
3
+ # Released under the MIT License.
4
+ # Copyright, 2012-2016, by Tony Arcieri.
5
+ # Copyright, 2012, by Ryan LeCompte.
6
+ # Copyright, 2012, by Nicholas Evans.
7
+ # Copyright, 2012, by Dimitrij Denissenko.
8
+ # Copyright, 2013, by Chuck Remes.
9
+ # Copyright, 2013, by Ron Evans.
10
+ # Copyright, 2013, by Sean Gregory.
11
+ # Copyright, 2013, by Utenmiki.
12
+ # Copyright, 2013, by Jeremy Hinegardner.
13
+ # Copyright, 2014, by Larry Lv.
14
+ # Copyright, 2014, by Bruno Enten.
15
+ # Copyright, 2014-2022, by Samuel Williams.
16
+ # Copyright, 2014, by Mike Bourgeous.
9
17
 
10
- require "timers/group"
11
- require "timers/wait"
18
+ require_relative "timers/version"
19
+
20
+ require_relative "timers/group"
21
+ require_relative "timers/wait"
data/license.md ADDED
@@ -0,0 +1,48 @@
1
+ # MIT License
2
+
3
+ Copyright, 2012-2017, by Tony Arcieri.
4
+ Copyright, 2012, by Ryan LeCompte.
5
+ Copyright, 2012, by Jesse Cooke.
6
+ Copyright, 2012, by Nicholas Evans.
7
+ Copyright, 2012, by Dimitrij Denissenko.
8
+ Copyright, 2013, by Chuck Remes.
9
+ Copyright, 2013, by Ron Evans.
10
+ Copyright, 2013, by Sean Gregory.
11
+ Copyright, 2013-2015, by Utenmiki.
12
+ Copyright, 2013, by Jeremy Hinegardner.
13
+ Copyright, 2014, by Larry Lv.
14
+ Copyright, 2014, by Bruno Enten.
15
+ Copyright, 2014-2022, by Samuel Williams.
16
+ Copyright, 2014, by Mike Bourgeous.
17
+ Copyright, 2014, by Klaus Trainer.
18
+ Copyright, 2014, by Lin Jen-Shin.
19
+ Copyright, 2014, by Lavir the Whiolet.
20
+ Copyright, 2015-2016, by Donovan Keme.
21
+ Copyright, 2015, by Tommy Ong Gia Phu.
22
+ Copyright, 2015, by Will Jessop.
23
+ Copyright, 2016, by Ryunosuke SATO.
24
+ Copyright, 2016, by Atul Bhosale.
25
+ Copyright, 2016, by Feram.
26
+ Copyright, 2017, by Vít Ondruch.
27
+ Copyright, 2017-2020, by Olle Jonsson.
28
+ Copyright, 2020, by Tim Smith.
29
+ Copyright, 2021, by Wander Hillen.
30
+ Copyright, 2022, by Yoshiki Takagi.
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining a copy
33
+ of this software and associated documentation files (the "Software"), to deal
34
+ in the Software without restriction, including without limitation the rights
35
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
36
+ copies of the Software, and to permit persons to whom the Software is
37
+ furnished to do so, subject to the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be included in all
40
+ copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
43
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
44
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
45
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
46
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
47
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
48
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,110 @@
1
+ # Timers
2
+
3
+ Collections of one-shot and periodic timers, intended for use with event loops such as [async](https://github.com/socketry/async).
4
+
5
+ [![Development Status](https://github.com/socketry/timers/workflows/Test/badge.svg)](https://github.com/socketry/timers/actions?workflow=Test)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ``` ruby
12
+ gem 'timers'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install timers
22
+
23
+ ## Usage
24
+
25
+ Create a new timer group with `Timers::Group.new`:
26
+
27
+ ``` ruby
28
+ require 'timers'
29
+
30
+ timers = Timers::Group.new
31
+ ```
32
+
33
+ Schedule a proc to run after 5 seconds with `Timers::Group#after`:
34
+
35
+ ``` ruby
36
+ five_second_timer = timers.after(5) { puts "Take five" }
37
+ ```
38
+
39
+ The `five_second_timer` variable is now bound to a Timers::Timer object. To
40
+ cancel a timer, use `Timers::Timer#cancel`
41
+
42
+ Once you've scheduled a timer, you can wait until the next timer fires with `Timers::Group#wait`:
43
+
44
+ ``` ruby
45
+ # Waits 5 seconds
46
+ timers.wait
47
+
48
+ # The script will now print "Take five"
49
+ ```
50
+
51
+ You can schedule a block to run periodically with `Timers::Group#every`:
52
+
53
+ ``` ruby
54
+ every_five_seconds = timers.every(5) { puts "Another 5 seconds" }
55
+
56
+ loop { timers.wait }
57
+ ```
58
+
59
+ You can also schedule a block to run immediately and periodically with `Timers::Group#now_and_every`:
60
+
61
+ ``` ruby
62
+ now_and_every_five_seconds = timers.now_and_every(5) { puts "Now and in another 5 seconds" }
63
+
64
+ loop { timers.wait }
65
+ ```
66
+
67
+ If you'd like another method to do the waiting for you, e.g. `Kernel.select`,
68
+ you can use `Timers::Group#wait_interval` to obtain the amount of time to wait. When
69
+ a timeout is encountered, you can fire all pending timers with `Timers::Group#fire`:
70
+
71
+ ``` ruby
72
+ loop do
73
+ interval = timers.wait_interval
74
+ ready_readers, ready_writers = select readers, writers, nil, interval
75
+
76
+ if ready_readers || ready_writers
77
+ # Handle IO
78
+ ...
79
+ else
80
+ # Timeout!
81
+ timers.fire
82
+ end
83
+ end
84
+ ```
85
+
86
+ You can also pause and continue individual timers, or all timers:
87
+
88
+ ``` ruby
89
+ paused_timer = timers.every(5) { puts "I was paused" }
90
+
91
+ paused_timer.pause
92
+ 10.times { timers.wait } # will not fire paused timer
93
+
94
+ paused_timer.resume
95
+ 10.times { timers.wait } # will fire timer
96
+
97
+ timers.pause
98
+ 10.times { timers.wait } # will not fire any timers
99
+
100
+ timers.resume
101
+ 10.times { timers.wait } # will fire all timers
102
+ ```
103
+
104
+ ## Contributing
105
+
106
+ 1. Fork it
107
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
108
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
109
+ 4. Push to the branch (`git push origin my-new-feature`)
110
+ 5. Create new Pull Request
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,15 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timers
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.3.0
4
+ version: 4.3.5
5
5
  platform: ruby
6
6
  authors:
7
- - Samuel Williams
8
7
  - Tony Arcieri
9
- autorequire:
8
+ - Samuel Williams
9
+ - "//de"
10
+ - Wander Hillen
11
+ - Jeremy Hinegardner
12
+ - skinnyjames
13
+ - Chuck Remes
14
+ - utenmiki
15
+ - Olle Jonsson
16
+ - deadprogrammer
17
+ - takiy33
18
+ - Larry Lv
19
+ - Lin Jen-Shin
20
+ - Ryunosuke SATO
21
+ - Tommy Ong Gia Phu
22
+ - Atul Bhosale
23
+ - Bruno Enten
24
+ - Dimitrij Denissenko
25
+ - Donovan Keme
26
+ - Feram
27
+ - Jesse Cooke
28
+ - Klaus Trainer
29
+ - Lavir the Whiolet
30
+ - Mike Bourgeous
31
+ - Ryan LeCompte
32
+ - Tim Smith
33
+ - Vít Ondruch
34
+ - Will Jessop
35
+ - Yoshiki Takagi
36
+ - nicholas a. evans
37
+ - tommyogp
38
+ autorequire:
10
39
  bindir: bin
11
- cert_chain: []
12
- date: 2019-01-21 00:00:00.000000000 Z
40
+ cert_chain:
41
+ - |
42
+ -----BEGIN CERTIFICATE-----
43
+ MIIE2DCCA0CgAwIBAgIBATANBgkqhkiG9w0BAQsFADBhMRgwFgYDVQQDDA9zYW11
44
+ ZWwud2lsbGlhbXMxHTAbBgoJkiaJk/IsZAEZFg1vcmlvbnRyYW5zZmVyMRIwEAYK
45
+ CZImiZPyLGQBGRYCY28xEjAQBgoJkiaJk/IsZAEZFgJuejAeFw0yMjA4MDYwNDUz
46
+ MjRaFw0zMjA4MDMwNDUzMjRaMGExGDAWBgNVBAMMD3NhbXVlbC53aWxsaWFtczEd
47
+ MBsGCgmSJomT8ixkARkWDW9yaW9udHJhbnNmZXIxEjAQBgoJkiaJk/IsZAEZFgJj
48
+ bzESMBAGCgmSJomT8ixkARkWAm56MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIB
49
+ igKCAYEAomvSopQXQ24+9DBB6I6jxRI2auu3VVb4nOjmmHq7XWM4u3HL+pni63X2
50
+ 9qZdoq9xt7H+RPbwL28LDpDNflYQXoOhoVhQ37Pjn9YDjl8/4/9xa9+NUpl9XDIW
51
+ sGkaOY0eqsQm1pEWkHJr3zn/fxoKPZPfaJOglovdxf7dgsHz67Xgd/ka+Wo1YqoE
52
+ e5AUKRwUuvaUaumAKgPH+4E4oiLXI4T1Ff5Q7xxv6yXvHuYtlMHhYfgNn8iiW8WN
53
+ XibYXPNP7NtieSQqwR/xM6IRSoyXKuS+ZNGDPUUGk8RoiV/xvVN4LrVm9upSc0ss
54
+ RZ6qwOQmXCo/lLcDUxJAgG95cPw//sI00tZan75VgsGzSWAOdjQpFM0l4dxvKwHn
55
+ tUeT3ZsAgt0JnGqNm2Bkz81kG4A2hSyFZTFA8vZGhp+hz+8Q573tAR89y9YJBdYM
56
+ zp0FM4zwMNEUwgfRzv1tEVVUEXmoFCyhzonUUw4nE4CFu/sE3ffhjKcXcY//qiSW
57
+ xm4erY3XAgMBAAGjgZowgZcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAwHQYDVR0O
58
+ BBYEFO9t7XWuFf2SKLmuijgqR4sGDlRsMC4GA1UdEQQnMCWBI3NhbXVlbC53aWxs
59
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MC4GA1UdEgQnMCWBI3NhbXVlbC53aWxs
60
+ aWFtc0BvcmlvbnRyYW5zZmVyLmNvLm56MA0GCSqGSIb3DQEBCwUAA4IBgQB5sxkE
61
+ cBsSYwK6fYpM+hA5B5yZY2+L0Z+27jF1pWGgbhPH8/FjjBLVn+VFok3CDpRqwXCl
62
+ xCO40JEkKdznNy2avOMra6PFiQyOE74kCtv7P+Fdc+FhgqI5lMon6tt9rNeXmnW/
63
+ c1NaMRdxy999hmRGzUSFjozcCwxpy/LwabxtdXwXgSay4mQ32EDjqR1TixS1+smp
64
+ 8C/NCWgpIfzpHGJsjvmH2wAfKtTTqB9CVKLCWEnCHyCaRVuKkrKjqhYCdmMBqCws
65
+ JkxfQWC+jBVeG9ZtPhQgZpfhvh+6hMhraUYRQ6XGyvBqEUe+yo6DKIT3MtGE2+CP
66
+ eX9i9ZWBydWb8/rvmwmX2kkcBbX0hZS1rcR593hGc61JR6lvkGYQ2MYskBveyaxt
67
+ Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
68
+ voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
69
+ -----END CERTIFICATE-----
70
+ date: 2022-10-12 00:00:00.000000000 Z
13
71
  dependencies:
14
72
  - !ruby/object:Gem::Dependency
15
73
  name: bundler
@@ -26,70 +84,82 @@ dependencies:
26
84
  - !ruby/object:Gem::Version
27
85
  version: '0'
28
86
  - !ruby/object:Gem::Dependency
29
- name: rspec
87
+ name: covered
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: bake-test
30
102
  requirement: !ruby/object:Gem::Requirement
31
103
  requirements:
32
104
  - - "~>"
33
105
  - !ruby/object:Gem::Version
34
- version: '3.6'
106
+ version: '0.1'
35
107
  type: :development
36
108
  prerelease: false
37
109
  version_requirements: !ruby/object:Gem::Requirement
38
110
  requirements:
39
111
  - - "~>"
40
112
  - !ruby/object:Gem::Version
41
- version: '3.6'
113
+ version: '0.1'
42
114
  - !ruby/object:Gem::Dependency
43
- name: rake
115
+ name: bake-test-external
44
116
  requirement: !ruby/object:Gem::Requirement
45
117
  requirements:
46
- - - ">="
118
+ - - "~>"
47
119
  - !ruby/object:Gem::Version
48
- version: '0'
120
+ version: '0.2'
49
121
  type: :development
50
122
  prerelease: false
51
123
  version_requirements: !ruby/object:Gem::Requirement
52
124
  requirements:
53
- - - ">="
125
+ - - "~>"
54
126
  - !ruby/object:Gem::Version
55
- version: '0'
56
- description: Schedule procs to run after a certain time, or at periodic intervals,
57
- using any API that accepts a timeout.
127
+ version: '0.2'
128
+ - !ruby/object:Gem::Dependency
129
+ name: sus
130
+ requirement: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - "~>"
133
+ - !ruby/object:Gem::Version
134
+ version: '0.13'
135
+ type: :development
136
+ prerelease: false
137
+ version_requirements: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '0.13'
142
+ description:
58
143
  email:
59
- - samuel@codeotaku.com
60
- - bascule@gmail.com
61
144
  executables: []
62
145
  extensions: []
63
146
  extra_rdoc_files: []
64
147
  files:
65
- - ".editorconfig"
66
- - ".gitignore"
67
- - ".rspec"
68
- - ".travis.yml"
69
- - Gemfile
70
- - README.md
71
- - Rakefile
72
148
  - lib/timers.rb
73
149
  - lib/timers/events.rb
74
150
  - lib/timers/group.rb
75
151
  - lib/timers/interval.rb
152
+ - lib/timers/priority_heap.rb
76
153
  - lib/timers/timer.rb
77
154
  - lib/timers/version.rb
78
155
  - lib/timers/wait.rb
79
- - spec/spec_helper.rb
80
- - spec/timers/cancel_spec.rb
81
- - spec/timers/events_spec.rb
82
- - spec/timers/every_spec.rb
83
- - spec/timers/group_spec.rb
84
- - spec/timers/performance_spec.rb
85
- - spec/timers/strict_spec.rb
86
- - spec/timers/wait_spec.rb
87
- - timers.gemspec
156
+ - license.md
157
+ - readme.md
88
158
  homepage: https://github.com/socketry/timers
89
159
  licenses:
90
160
  - MIT
91
161
  metadata: {}
92
- post_install_message:
162
+ post_install_message:
93
163
  rdoc_options: []
94
164
  require_paths:
95
165
  - lib
@@ -97,23 +167,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
97
167
  requirements:
98
168
  - - ">="
99
169
  - !ruby/object:Gem::Version
100
- version: 2.2.1
170
+ version: '0'
101
171
  required_rubygems_version: !ruby/object:Gem::Requirement
102
172
  requirements:
103
173
  - - ">="
104
174
  - !ruby/object:Gem::Version
105
175
  version: '0'
106
176
  requirements: []
107
- rubygems_version: 3.0.1
108
- signing_key:
177
+ rubygems_version: 3.3.7
178
+ signing_key:
109
179
  specification_version: 4
110
- summary: Pure Ruby one-shot and periodic timers
111
- test_files:
112
- - spec/spec_helper.rb
113
- - spec/timers/cancel_spec.rb
114
- - spec/timers/events_spec.rb
115
- - spec/timers/every_spec.rb
116
- - spec/timers/group_spec.rb
117
- - spec/timers/performance_spec.rb
118
- - spec/timers/strict_spec.rb
119
- - spec/timers/wait_spec.rb
180
+ summary: Pure Ruby one-shot and periodic timers.
181
+ test_files: []
metadata.gz.sig ADDED
Binary file
data/.editorconfig DELETED
@@ -1,6 +0,0 @@
1
- root = true
2
-
3
- [*]
4
- indent_style = tab
5
- indent_size = 2
6
-
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --warnings
3
- --require spec_helper
data/.travis.yml DELETED
@@ -1,20 +0,0 @@
1
- language: ruby
2
- dist: xenial
3
- cache: bundler
4
-
5
- matrix:
6
- include:
7
- - rvm: 2.3
8
- - rvm: 2.4
9
- - rvm: 2.5
10
- - rvm: 2.6
11
- - rvm: jruby-head
12
- env: JRUBY_OPTS="--debug -X+O"
13
- - rvm: truffleruby
14
- - rvm: ruby-head
15
- - rvm: rbx-3
16
- allow_failures:
17
- - rvm: ruby-head
18
- - rvm: jruby-head
19
- - rvm: rbx-3
20
- - rvm: truffleruby
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'pry'
7
- end
8
-
9
- group :test do
10
- gem 'benchmark-ips'
11
-
12
- gem "ruby-prof", platform: :mri
13
- gem 'simplecov', platform: :mri
14
- gem 'coveralls', platform: :mri
15
- end
data/README.md DELETED
@@ -1,149 +0,0 @@
1
- # Timers
2
-
3
- Collections of one-shot and periodic timers, intended for use with event loops such as [async].
4
-
5
- [![Build Status](https://secure.travis-ci.org/socketry/timers.svg)](https://travis-ci.org/socketry/timers)
6
- [![Code Climate](https://codeclimate.com/github/socketry/timers.svg)](https://codeclimate.com/github/socketry/timers)
7
- [![Coverage Status](https://coveralls.io/repos/socketry/timers/badge.svg)](https://coveralls.io/r/socketry/timers)
8
-
9
- [async]: https://github.com/socketry/async
10
-
11
- ## Installation
12
-
13
- Add this line to your application's Gemfile:
14
-
15
- ```ruby
16
- gem 'timers'
17
- ```
18
-
19
- And then execute:
20
-
21
- $ bundle
22
-
23
- Or install it yourself as:
24
-
25
- $ gem install timers
26
-
27
- ## Usage
28
-
29
- Create a new timer group with `Timers::Group.new`:
30
-
31
- ```ruby
32
- require 'timers'
33
-
34
- timers = Timers::Group.new
35
- ```
36
-
37
- Schedule a proc to run after 5 seconds with `Timers::Group#after`:
38
-
39
- ```ruby
40
- five_second_timer = timers.after(5) { puts "Take five" }
41
- ```
42
-
43
- The `five_second_timer` variable is now bound to a Timers::Timer object. To
44
- cancel a timer, use `Timers::Timer#cancel`
45
-
46
- Once you've scheduled a timer, you can wait until the next timer fires with `Timers::Group#wait`:
47
-
48
- ```ruby
49
- # Waits 5 seconds
50
- timers.wait
51
-
52
- # The script will now print "Take five"
53
- ```
54
-
55
- You can schedule a block to run periodically with `Timers::Group#every`:
56
-
57
- ```ruby
58
- every_five_seconds = timers.every(5) { puts "Another 5 seconds" }
59
-
60
- loop { timers.wait }
61
- ```
62
-
63
- You can also schedule a block to run immediately and periodically with `Timers::Group#now_and_every`:
64
- ```ruby
65
- now_and_every_five_seconds = timers.now_and_every(5) { puts "Now and in another 5 seconds" }
66
-
67
- loop { timers.wait }
68
- ```
69
-
70
- If you'd like another method to do the waiting for you, e.g. `Kernel.select`,
71
- you can use `Timers::Group#wait_interval` to obtain the amount of time to wait. When
72
- a timeout is encountered, you can fire all pending timers with `Timers::Group#fire`:
73
-
74
- ```ruby
75
- loop do
76
- interval = timers.wait_interval
77
- ready_readers, ready_writers = select readers, writers, nil, interval
78
-
79
- if ready_readers || ready_writers
80
- # Handle IO
81
- ...
82
- else
83
- # Timeout!
84
- timers.fire
85
- end
86
- end
87
- ```
88
-
89
- You can also pause and continue individual timers, or all timers:
90
-
91
- ```ruby
92
- paused_timer = timers.every(5) { puts "I was paused" }
93
-
94
- paused_timer.pause
95
- 10.times { timers.wait } # will not fire paused timer
96
-
97
- paused_timer.resume
98
- 10.times { timers.wait } # will fire timer
99
-
100
- timers.pause
101
- 10.times { timers.wait } # will not fire any timers
102
-
103
- timers.resume
104
- 10.times { timers.wait } # will fire all timers
105
- ```
106
-
107
- ## Contributing
108
-
109
- 1. Fork it
110
- 2. Create your feature branch (`git checkout -b my-new-feature`)
111
- 3. Commit your changes (`git commit -am 'Add some feature'`)
112
- 4. Push to the branch (`git push origin my-new-feature`)
113
- 5. Create new Pull Request
114
-
115
- ## License
116
-
117
- Released under the MIT license.
118
-
119
- Copyright, 2018, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams).
120
- Copyright, 2016, by [Tony Arcieri](bascule@gmail.com).
121
- Copyright, 2016, by Jeremy Hinegardner.
122
- Copyright, 2016, by Sean Gregory.
123
- Copyright, 2016, by Chuck Remes.
124
- Copyright, 2016, by Utenmiki.
125
- Copyright, 2016, by Ron Evans.
126
- Copyright, 2016, by Larry Lv.
127
- Copyright, 2016, by Bruno Enten.
128
- Copyright, 2016, by Jesse Cooke.
129
- Copyright, 2016, by Nicholas Evans.
130
- Copyright, 2016, by Dimitrij Denissenko.
131
- Copyright, 2016, by Ryan LeCompte.
132
-
133
- Permission is hereby granted, free of charge, to any person obtaining a copy
134
- of this software and associated documentation files (the "Software"), to deal
135
- in the Software without restriction, including without limitation the rights
136
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
137
- copies of the Software, and to permit persons to whom the Software is
138
- furnished to do so, subject to the following conditions:
139
-
140
- The above copyright notice and this permission notice shall be included in
141
- all copies or substantial portions of the Software.
142
-
143
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
144
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
145
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
146
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
147
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
148
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
149
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:test)
5
-
6
- task :default => :test