wires 0.1.4 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 660935c436c6c57687e2c3c8a506d9810e478789
4
- data.tar.gz: e2cd88acddaade081ca3da917f885e40845d2282
3
+ metadata.gz: ffc466f024c5e1a6e59c435d1849af75dd19bf0c
4
+ data.tar.gz: 34336c47982369319a614836b310442e5774e22f
5
5
  SHA512:
6
- metadata.gz: addb4f0b4d550fa8e2d45d3124900a9a4a605c65ac05ebf10206bef54bffa23b6666ad4381ba675232e081fa75936e6e63639247f37f17b9c432852fa815477c
7
- data.tar.gz: 670c122be77ebde3f81e87efb1d1317a526624cddb139c2e9ea9b988f5c1405b1c682b1f6c497c4e79a1b61fc9599b6fe0819a1c4eeaa8394fcaf2fdffb7fb6d
6
+ metadata.gz: 38e0d5dc15c590d25639f311e9a1029f358975343e174b342365ee1cbb8f6069a6bbf2a31acff62a83d2867a4f34292f82cf4d1eabc91709e204fca1adfc318f
7
+ data.tar.gz: 68a7b2f5dcde44efb7c8553de8748acfb65ee949b3fb0a471035a13e1826d4bad88a4b4dbe1f60a65a356fedf16359e62af3d6e402b18d73d12210fafcf7f35c
@@ -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
- @@channel_list = Set.new
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
- if not (inst = (@@channel_list.select {|x| \
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 @@channel_list if self==@@channel_star
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 @@channel_list
92
+ for c in @@channel_hash.values
97
93
  relevant << c if \
98
- (c.name.is_a?(Regexp) ?
99
- self.name =~ c.name :
100
- self.name.to_s == c.name.to_s)
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() @@keepgoing=false end
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
- sleep # yield to event loop thread until awoken by it later
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
- @@keepgoing = true
35
+ @@running = true
34
36
 
35
- while @@keepgoing
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
- @keepgoing = false
53
+ @running = false
52
54
  unhandled_exception(e)
53
55
 
54
56
  rescue Exception => e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wires
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe McIlvain