event_timer 1.0.0
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 +15 -0
- data/lib/event_timer.rb +48 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MDhhZDAyNjZiNjEwOWEzZTg1YjEwOGEzYjQ1MTNhMmQ2NTM5YjBlYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGY2NDRiMmZkZWViMTlhZmE0ZGEwN2E1NjY3YmQyYTU5Mzk0YTVkZg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTRlMmVjN2ZkNTcwMzcyMmMxNDdkYzY1ZDE1OGU5NWMxMTk2MThiMTA5YzE3
|
10
|
+
NzUxNmUyZGJkMzFmZjc5NDQ5ZmYxNGEwZWExZjUzMmU3ZjgzOWVlYWFmZmI5
|
11
|
+
MmQ0ODFhOTE2NjIyOGQ2NDU5NGRjOTEyYTI3MGZjODVlNzc4Y2I=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ODhlYzYyMTQ3YmZhM2VjZjM2MzA3ZDE1ZTJjNzkyYTJlNTVmOTE2Nzc2Mzc2
|
14
|
+
NDYyMzNmYTg4ZDRhNDU4Yzg1NGY2ZjFkZjk3Y2UwYzE0Zjg4YzkwYTBiN2Yz
|
15
|
+
MjNkZTU4MzU2YmJlMTA3MjY2NzY1NzJiNThjM2IyYTg0MjRhNzQ=
|
data/lib/event_timer.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'ready_pool'
|
2
|
+
require 'async_emitter'
|
3
|
+
|
4
|
+
class EventTimer < AsyncEmitter
|
5
|
+
def initialize (num_timers)
|
6
|
+
super()
|
7
|
+
@pool = ReadyPool.new num_timers, lambda { |args| timer_proc args }
|
8
|
+
@th_args = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def start (event, time, data)
|
12
|
+
args = {
|
13
|
+
:event => event,
|
14
|
+
:time => time,
|
15
|
+
:data => data,
|
16
|
+
:cancel => false,
|
17
|
+
:mutex => Mutex.new
|
18
|
+
}
|
19
|
+
|
20
|
+
@th_args[args[:event]] = args
|
21
|
+
|
22
|
+
@pool.start args
|
23
|
+
end
|
24
|
+
|
25
|
+
def cancel (event)
|
26
|
+
@th_args[event][:mutex].synchronize do
|
27
|
+
@th_args[event][:cancel] = true
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def timer_proc (args)
|
33
|
+
sleep args[:time]
|
34
|
+
|
35
|
+
args[:mutex].synchronize do
|
36
|
+
if args[:cancel]
|
37
|
+
@th_args.delete args[:event]
|
38
|
+
return
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
emit args[:event], args[:data]
|
43
|
+
|
44
|
+
@th_args.delete args[:event]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: event_timer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Greg Martin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: async_emitter
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.1.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.1'
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.1.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: ready_pool
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.1'
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 1.1.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ~>
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '1.1'
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 1.1.0
|
53
|
+
description: An event timer for Ruby
|
54
|
+
email: greg@softsprocket.com
|
55
|
+
executables: []
|
56
|
+
extensions: []
|
57
|
+
extra_rdoc_files: []
|
58
|
+
files:
|
59
|
+
- lib/event_timer.rb
|
60
|
+
homepage: http://rubygems.org/gems/event_timer.rb
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: EventTimer
|
84
|
+
test_files: []
|
85
|
+
has_rdoc:
|