channels 0.0.2 → 0.0.3
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/channel.rb +20 -1
- data/lib/main_channel.rb +7 -0
- metadata +2 -1
data/lib/channel.rb
CHANGED
@@ -8,6 +8,7 @@ class Channel
|
|
8
8
|
@mutex = Mutex.new
|
9
9
|
@sender = nil
|
10
10
|
@value = []
|
11
|
+
@subchannels = {}
|
11
12
|
@write_mutex = Mutex.new
|
12
13
|
if block_given?
|
13
14
|
@thread = new_thread { yield self }
|
@@ -64,8 +65,26 @@ class Channel
|
|
64
65
|
}
|
65
66
|
end
|
66
67
|
|
67
|
-
|
68
68
|
def kill
|
69
69
|
@thread.kill
|
70
70
|
end
|
71
|
+
|
72
|
+
def add_subchannel(channel, &block)
|
73
|
+
@subchannels[channel] = block
|
74
|
+
end
|
75
|
+
|
76
|
+
def remove_subchannel(channel)
|
77
|
+
channel.kill
|
78
|
+
@subchannels[channel] = nil
|
79
|
+
end
|
80
|
+
|
81
|
+
def process
|
82
|
+
result = self.read
|
83
|
+
function = @subchannels[self.sender]
|
84
|
+
begin
|
85
|
+
instance_exec result, self.sender, &function
|
86
|
+
rescue => e
|
87
|
+
puts "got an error #{e.inspect}"
|
88
|
+
end
|
89
|
+
end
|
71
90
|
end
|
data/lib/main_channel.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: channels
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- lib/channel.rb
|
21
21
|
- lib/channels.rb
|
22
|
+
- lib/main_channel.rb
|
22
23
|
homepage: http://rubygems.org/gems/channels
|
23
24
|
licenses:
|
24
25
|
- MIT
|