wires 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 +4 -4
- data/lib/wires/hub.rb +29 -37
- data/lib/wires/time.rb +7 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63192901a598961c0bd3aafa25c6e49da1e4d328
|
4
|
+
data.tar.gz: 5477285e774357f9d62fa7f41088a7ad16f7f90d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00163b5c1c47e4037c8db05a3338bdaeeca7541dbc0949995f60aa167120c31a2cdd4c23e6100403668dbeb0cb13f93a6a43a08873a019dfc49af42aa1e63f41
|
7
|
+
data.tar.gz: 36a4df0cd53af0005e2459847e44e5220062699e0255ef0c0f904e5ac02a4c8e43928846e6bc78127e4e67d8d98bf4da733bb87b6069b4460af5692b9ea0677b
|
data/lib/wires/hub.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
|
2
|
-
#
|
3
|
-
def puts(x) $stdout.puts(x) end
|
4
|
-
|
2
|
+
#TODO: Allow custom grain times
|
5
3
|
module Wires
|
6
4
|
# An Event Hub. Event/proc associations come in, and the procs
|
7
5
|
# get called in new threads in the order received
|
@@ -27,25 +25,15 @@ module Wires
|
|
27
25
|
@at_exit = Proc.new{nil}
|
28
26
|
at_exit do self.at_exit_proc end
|
29
27
|
|
30
|
-
@fire_proc_alive = Proc.new do |x|
|
31
|
-
@queue << [x, Thread.current]
|
32
|
-
@thread.wakeup
|
33
|
-
sleep
|
34
|
-
end
|
35
|
-
@fire_proc_dead = Proc.new do |x|
|
36
|
-
@queue << [x, nil]
|
37
|
-
end
|
38
|
-
@fire_proc = @fire_proc_dead
|
39
|
-
|
40
28
|
state_machine_init
|
29
|
+
|
41
30
|
nil end
|
42
31
|
|
43
|
-
def at_exit_proc; @at_exit.call;
|
32
|
+
def at_exit_proc; @at_exit.call; end
|
44
33
|
|
45
34
|
# Make subclasses call class_init
|
46
|
-
def inherited(subcls)
|
47
|
-
|
48
|
-
end
|
35
|
+
def inherited(subcls); subcls.class_init end
|
36
|
+
|
49
37
|
|
50
38
|
def dead?; state==:dead end
|
51
39
|
def alive?; state==:alive end
|
@@ -59,24 +47,30 @@ module Wires
|
|
59
47
|
# specified, the Hub event loop is run in a new thread,
|
60
48
|
# which the main thread joins in at_exit.
|
61
49
|
def run(*flags)
|
62
|
-
|
50
|
+
sleep 0 until request_state :alive
|
51
|
+
sleep 0 until @thread
|
63
52
|
|
64
53
|
# If :blocking, block now, else block at exit
|
65
54
|
(flags.include? :in_place) ?
|
66
55
|
(@thread.join) :
|
67
56
|
(@at_exit = Proc.new { @thread.join if @thread and not $! })
|
57
|
+
|
68
58
|
end
|
69
59
|
|
70
60
|
##
|
71
61
|
# Kill the Hub event loop (optional flags change thread behavior)
|
72
62
|
#
|
73
63
|
# valid flags:
|
74
|
-
# [+:
|
75
|
-
#
|
64
|
+
# [+:nonblocking+]
|
65
|
+
# Without this flag, calling thread will be blocked
|
66
|
+
# until Hub thread is done
|
67
|
+
# [+:purge_events+]
|
68
|
+
# Without this flag, Hub thread won't be done
|
69
|
+
# until all child threads are done
|
76
70
|
def kill(*flags)
|
77
|
-
@please_finish_all = (flags.include? :
|
71
|
+
@please_finish_all = (not flags.include? :purge_events)
|
78
72
|
@please_kill = true
|
79
|
-
block_until_state :dead
|
73
|
+
block_until_state :dead unless (flags.include? :nonblocking)
|
80
74
|
nil end
|
81
75
|
|
82
76
|
# Register hook to execute before run - can call multiple times
|
@@ -115,11 +109,10 @@ module Wires
|
|
115
109
|
|
116
110
|
@queue << [x, Thread.current]
|
117
111
|
(x[2] and @thread) ?
|
118
|
-
sleep
|
112
|
+
sleep :
|
119
113
|
Thread.pass
|
120
114
|
|
121
115
|
nil end
|
122
|
-
# threadlock :fire, lock: :@child_threads_lock
|
123
116
|
def <<(x); fire(x); end
|
124
117
|
|
125
118
|
def flush_queue
|
@@ -227,22 +220,22 @@ module Wires
|
|
227
220
|
transition_to :alive do
|
228
221
|
before { run_hooks @before_runs }
|
229
222
|
after { run_hooks @after_runs }
|
230
|
-
after {
|
231
|
-
after { start_hegemon_auto_thread(0.1) }
|
232
|
-
# after { @fire_proc = @fire_proc_alive }
|
223
|
+
after { start_hegemon_auto_thread(0.05) }
|
233
224
|
end
|
234
225
|
end
|
235
226
|
|
236
227
|
declare_state :alive do
|
237
228
|
|
238
229
|
task do |i|
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
230
|
+
if i==0
|
231
|
+
@thread_continue = true
|
232
|
+
@thread = Thread.new do
|
233
|
+
while @thread_continue
|
234
|
+
if @queue.empty? then sleep 0.01
|
235
|
+
else process_item(@queue.shift) end
|
236
|
+
end
|
244
237
|
end
|
245
|
-
end
|
238
|
+
end
|
246
239
|
|
247
240
|
end
|
248
241
|
|
@@ -253,17 +246,16 @@ module Wires
|
|
253
246
|
|
254
247
|
before { join_children if @please_finish_all }
|
255
248
|
|
256
|
-
after { @
|
249
|
+
after { @thread_continue=false
|
250
|
+
@thread.join
|
251
|
+
@thread = nil }
|
257
252
|
|
258
253
|
after { @please_kill = false }
|
259
254
|
after { @please_finish_all = false }
|
260
255
|
|
261
256
|
after { run_hooks @after_kills }
|
262
257
|
|
263
|
-
# after { @fire_proc = @fire_proc_dead }
|
264
|
-
|
265
258
|
after { end_hegemon_auto_thread }
|
266
|
-
after { do_state_tasks }
|
267
259
|
end
|
268
260
|
end
|
269
261
|
|
data/lib/wires/time.rb
CHANGED
@@ -135,7 +135,6 @@ module Wires
|
|
135
135
|
:schedule_pull,
|
136
136
|
lock: :@schedule_lock
|
137
137
|
|
138
|
-
# Do scheduled firing of events as long as Hub is alive
|
139
138
|
def main_loop
|
140
139
|
|
141
140
|
@keepgoing = true
|
@@ -174,16 +173,18 @@ module Wires
|
|
174
173
|
# on :time_scheduler_start, self do; main_loop; end;
|
175
174
|
# Channel.new(self).fire(:time_scheduler_start)
|
176
175
|
|
176
|
+
# Refire the start event after Hub dies in case it restarts
|
177
|
+
Hub.after_run(retain:true) do
|
178
|
+
@thread = Thread.new { main_loop }
|
179
|
+
end
|
180
|
+
|
177
181
|
# Stop the main loop upon death of Hub
|
178
182
|
Hub.before_kill(retain:true) do
|
179
183
|
sleep 0 until @sleepzone==true
|
184
|
+
sleep 0 until @thread.status=='sleep'
|
180
185
|
@keepgoing=false
|
181
186
|
wakeup
|
182
|
-
|
183
|
-
|
184
|
-
# Refire the start event after Hub dies in case it restarts
|
185
|
-
Hub.after_run(retain:true) do
|
186
|
-
@thread = Thread.new { main_loop }
|
187
|
+
@thread.join
|
187
188
|
end
|
188
189
|
|
189
190
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wires
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.0.
|
33
|
+
version: 0.0.7
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.0.
|
40
|
+
version: 0.0.7
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|