wires 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wires/channels.rb +12 -11
- data/lib/wires/hub.rb +7 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ffc466f024c5e1a6e59c435d1849af75dd19bf0c
|
4
|
+
data.tar.gz: 34336c47982369319a614836b310442e5774e22f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38e0d5dc15c590d25639f311e9a1029f358975343e174b342365ee1cbb8f6069a6bbf2a31acff62a83d2867a4f34292f82cf4d1eabc91709e204fca1adfc318f
|
7
|
+
data.tar.gz: 68a7b2f5dcde44efb7c8553de8748acfb65ee949b3fb0a471035a13e1826d4bad88a4b4dbe1f60a65a356fedf16359e62af3d6e402b18d73d12210fafcf7f35c
|
data/lib/wires/channels.rb
CHANGED
@@ -29,15 +29,11 @@ class Channel
|
|
29
29
|
nil end
|
30
30
|
|
31
31
|
# Ensure that there is only one instance of Channel per name
|
32
|
-
@@
|
32
|
+
@@channel_hash = Hash.new
|
33
33
|
@@new_lock = Mutex.new
|
34
34
|
def self.new(*args, &block)
|
35
35
|
@@new_lock.synchronize do
|
36
|
-
|
37
|
-
(x.name==args[0] and x.name.class==args[0].class)} [0]))
|
38
|
-
@@channel_list << (inst = super(*args, &block))
|
39
|
-
end
|
40
|
-
inst
|
36
|
+
@@channel_hash[args[0]] ||= super(*args, &block)
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
@@ -86,18 +82,23 @@ class Channel
|
|
86
82
|
nil end
|
87
83
|
|
88
84
|
def relevant_channels
|
89
|
-
return @@
|
85
|
+
return @@channel_hash.values if self==@@channel_star
|
90
86
|
|
91
87
|
if self.name.is_a?(Regexp) then raise TypeError,
|
92
88
|
"Cannot fire on Regexp channel: #{self.name}."\
|
93
89
|
" Regexp channels can only used in event handlers." end
|
94
90
|
|
95
91
|
relevant = [@@channel_star]
|
96
|
-
for c in @@
|
92
|
+
for c in @@channel_hash.values
|
97
93
|
relevant << c if \
|
98
|
-
|
99
|
-
self.name =~ c.name
|
100
|
-
|
94
|
+
if c.name.is_a?(Regexp)
|
95
|
+
self.name =~ c.name
|
96
|
+
elsif (defined?(c.name.channel_name) and
|
97
|
+
defined?(self.name.channel_name))
|
98
|
+
self.name.channel_name == c.name.channel_name
|
99
|
+
else
|
100
|
+
self.name.to_s == c.name.to_s
|
101
|
+
end
|
101
102
|
end
|
102
103
|
return relevant.uniq
|
103
104
|
end
|
data/lib/wires/hub.rb
CHANGED
@@ -7,6 +7,7 @@ def puts(x) $stdout.puts(x) end
|
|
7
7
|
# get called in new threads in the order received
|
8
8
|
class Hub
|
9
9
|
@@queue = Queue.new
|
10
|
+
@@running = false
|
10
11
|
|
11
12
|
# Start the Hub event loop in a new thread
|
12
13
|
def self.run
|
@@ -18,21 +19,22 @@ class Hub
|
|
18
19
|
def self.run_in_place() self.run_loop() end
|
19
20
|
|
20
21
|
# Kill the Hub event loop (softly)
|
21
|
-
def self.kill() @@
|
22
|
+
def self.kill() @@running=false end
|
22
23
|
|
23
24
|
# Put x in the queue, and block until x is processed
|
24
25
|
def self.fire(x)
|
25
26
|
@@queue << [x, Thread.current]
|
26
|
-
|
27
|
+
# yield to event loop thread until awoken by it later
|
28
|
+
sleep unless not @@running
|
27
29
|
end
|
28
30
|
def self.<<(x) fire(x) end
|
29
31
|
|
30
32
|
private
|
31
33
|
|
32
34
|
def self.run_loop
|
33
|
-
@@
|
35
|
+
@@running = true
|
34
36
|
|
35
|
-
while @@
|
37
|
+
while @@running
|
36
38
|
if @@queue.empty? then sleep(0)
|
37
39
|
else process_item(@@queue.shift) end
|
38
40
|
end
|
@@ -48,7 +50,7 @@ private
|
|
48
50
|
waiting_thread.wakeup if blocking
|
49
51
|
|
50
52
|
rescue Interrupt, SystemExit => e
|
51
|
-
@
|
53
|
+
@running = false
|
52
54
|
unhandled_exception(e)
|
53
55
|
|
54
56
|
rescue Exception => e
|