ruby_channel 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/README +41 -2
- data/lib/ruby_channel/channel.rb +2 -2
- data/lib/ruby_channel/selector.rb +1 -1
- data/lib/ruby_channel/version.rb +1 -1
- metadata +3 -3
data/.gitignore
CHANGED
data/README
CHANGED
@@ -1,7 +1,46 @@
|
|
1
|
+
= Ruby Channel - The power of Go Channels in Ruby
|
2
|
+
|
1
3
|
This is a simple library aimed to use channels in Ruby the same concept that channels in Google's Go.
|
2
4
|
|
3
|
-
Missing tests and decent README? Read the very simple code!
|
4
5
|
|
5
|
-
|
6
|
+
== Install
|
7
|
+
|
8
|
+
gem install ruby_channel
|
9
|
+
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
This is the simplest example:
|
14
|
+
|
15
|
+
include RubyChannel
|
16
|
+
|
17
|
+
chan = Channel.new
|
18
|
+
chan << 'data'
|
19
|
+
chan.pop # => 'data'
|
20
|
+
|
21
|
+
Now something more interesting:
|
22
|
+
|
23
|
+
include RubyChannel
|
24
|
+
chan = [Channel.new, Channel.new]
|
25
|
+
|
26
|
+
Thread.new{ chan[rand 2] << 'where data goes?' }
|
27
|
+
|
28
|
+
select_channel do |s|
|
29
|
+
s.listen(chan[0]){ |data| puts data; puts 'On channel zero!' }
|
30
|
+
s.listen(chan[1]){ |data| puts data; puts 'On channel one!' }
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
== Documentation
|
35
|
+
|
36
|
+
Look at http://rdoc.info/gems/ruby_channel
|
37
|
+
|
38
|
+
|
39
|
+
== TODO
|
40
|
+
|
41
|
+
* Tests (Shame on me!)
|
42
|
+
|
43
|
+
|
44
|
+
== License
|
6
45
|
|
7
46
|
MIT license... bla, bla, bla
|
data/lib/ruby_channel/channel.rb
CHANGED
@@ -49,8 +49,8 @@ module RubyChannel
|
|
49
49
|
end
|
50
50
|
|
51
51
|
#
|
52
|
-
# Retrieves data from channel like method +pop+, but if
|
53
|
-
#
|
52
|
+
# Retrieves data from channel like method +pop+, but if thread isn't suspended,
|
53
|
+
# and an exception is raised.
|
54
54
|
#
|
55
55
|
def pop!
|
56
56
|
@mutex.synchronize do
|
data/lib/ruby_channel/version.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dalton Pinto
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-10 00:00:00 -02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|