channels 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/channel.rb +20 -1
  2. data/lib/main_channel.rb +7 -0
  3. metadata +2 -1
@@ -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
@@ -0,0 +1,7 @@
1
+ class MainChannel < Channel
2
+ def run
3
+ loop do
4
+ process
5
+ end
6
+ end
7
+ end
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.2
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