ichannel 3.0.2 → 3.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardopts +1 -1
- data/Gemfile +5 -1
- data/lib/ichannel.rb +43 -33
- data/lib/ichannel/version.rb +1 -1
- metadata +5 -4
data/.yardopts
CHANGED
data/Gemfile
CHANGED
data/lib/ichannel.rb
CHANGED
@@ -25,8 +25,10 @@ class IChannel
|
|
25
25
|
# Returns nil when the channel is already closed.
|
26
26
|
#
|
27
27
|
def close
|
28
|
-
|
29
|
-
|
28
|
+
unless closed?
|
29
|
+
@reader.close
|
30
|
+
@writer.close
|
31
|
+
true
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -40,38 +42,43 @@ class IChannel
|
|
40
42
|
# An object to add to the channel.
|
41
43
|
#
|
42
44
|
def write(object)
|
43
|
-
|
44
|
-
raise IOError, 'The channel cannot be written to (closed).'
|
45
|
-
end
|
46
|
-
_, writable, _ = IO.select [], [@writer], []
|
47
|
-
writable[0].send @serializer.dump(object), 0
|
45
|
+
write!(object, nil)
|
48
46
|
end
|
49
47
|
alias_method :put, :write
|
50
48
|
|
51
49
|
#
|
52
50
|
# Add an object to the channel.
|
53
51
|
#
|
54
|
-
# Unlike {#
|
55
|
-
# this method will raise an IOError
|
56
|
-
# remains unwritable.
|
52
|
+
# Unlike {#write}, which waits indefinitely until the channel becomes writable,
|
53
|
+
# this method will raise an IOError when _timeout_ seconds elapse and
|
54
|
+
# the channel remains unwritable.
|
57
55
|
#
|
58
|
-
# @
|
59
|
-
#
|
56
|
+
# @param
|
57
|
+
# (see IChannel#write)
|
58
|
+
#
|
59
|
+
# @param [Numeric] timeout
|
60
|
+
# The number of seconds to wait for the channel to become writable.
|
61
|
+
#
|
62
|
+
# @raise (see IChannel#write)
|
60
63
|
#
|
61
|
-
# @
|
64
|
+
# @raise [IOError]
|
65
|
+
# When _timeout_ seconds elapse & the channel remains unwritable.
|
62
66
|
#
|
63
|
-
def write!(object)
|
64
|
-
|
67
|
+
def write!(object, timeout = 0.1)
|
68
|
+
if @writer.closed?
|
69
|
+
raise IOError, 'The channel cannot be written to (closed).'
|
70
|
+
end
|
71
|
+
_, writable, _ = IO.select [], [@writer], [], timeout
|
65
72
|
if writable
|
66
|
-
writable[0].send @serializer.dump(
|
73
|
+
writable[0].send @serializer.dump(object), 0
|
67
74
|
else
|
68
75
|
raise IOError, 'The channel cannot be written to.'
|
69
76
|
end
|
70
77
|
end
|
71
|
-
alias_method :put!, :write
|
78
|
+
alias_method :put!, :write!
|
72
79
|
|
73
80
|
#
|
74
|
-
# Receive
|
81
|
+
# Receive an object from the channel.
|
75
82
|
#
|
76
83
|
# @raise [IOError]
|
77
84
|
# When the channel is closed.
|
@@ -80,30 +87,34 @@ class IChannel
|
|
80
87
|
# The object read from the channel.
|
81
88
|
#
|
82
89
|
def recv
|
83
|
-
|
84
|
-
raise IOError, 'The channel cannot be read from (closed).'
|
85
|
-
end
|
86
|
-
readable, _ = IO.select [@reader], [], []
|
87
|
-
msg, _ = readable[0].recvmsg
|
88
|
-
@serializer.load msg
|
90
|
+
recv!(nil)
|
89
91
|
end
|
90
92
|
alias_method :get, :recv
|
91
93
|
|
92
94
|
#
|
93
|
-
# Receive
|
95
|
+
# Receive an object from the channel.
|
94
96
|
#
|
95
|
-
# Unlike {#
|
96
|
-
# this method will raise an IOError
|
97
|
-
# remains unreadable.
|
97
|
+
# Unlike {#recv}, which waits indefinitely until the channel becomes readable,
|
98
|
+
# this method will raise an IOError when _timeout_ seconds elapse and the
|
99
|
+
# channel remains unreadable.
|
98
100
|
#
|
101
|
+
# @param [Numeric] timeout
|
102
|
+
# The number of seconds to wait for the channel to become readable.
|
103
|
+
#
|
99
104
|
# @raise [IOError]
|
100
|
-
#
|
101
|
-
#
|
105
|
+
# (see IChannel#recv)
|
106
|
+
#
|
107
|
+
# @raise [IOError]
|
108
|
+
# When _timeout_ seconds elapse & the channel remains unreadable.
|
109
|
+
#
|
102
110
|
# @return [Object]
|
103
111
|
# The object read from the channel.
|
104
112
|
#
|
105
|
-
def recv!
|
106
|
-
|
113
|
+
def recv!(timeout = 0.1)
|
114
|
+
if @reader.closed?
|
115
|
+
raise IOError, 'The channel cannot be read from (closed).'
|
116
|
+
end
|
117
|
+
readable, _ = IO.select [@reader], [], [], timeout
|
107
118
|
if readable
|
108
119
|
msg, _ = readable[0].recvmsg
|
109
120
|
@serializer.load msg
|
@@ -112,5 +123,4 @@ class IChannel
|
|
112
123
|
end
|
113
124
|
end
|
114
125
|
alias_method :get!, :recv!
|
115
|
-
|
116
126
|
end
|
data/lib/ichannel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ichannel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-24 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! "A modern and easy-to-use interprocess communication \n primitive."
|
15
15
|
email:
|
@@ -44,7 +44,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
44
|
version: '0'
|
45
45
|
segments:
|
46
46
|
- 0
|
47
|
-
hash:
|
47
|
+
hash: 3488469513037529160
|
48
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -53,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
53
|
version: '0'
|
54
54
|
segments:
|
55
55
|
- 0
|
56
|
-
hash:
|
56
|
+
hash: 3488469513037529160
|
57
57
|
requirements: []
|
58
58
|
rubyforge_project:
|
59
59
|
rubygems_version: 1.8.23
|
@@ -63,3 +63,4 @@ summary: A modern and easy-to-use interprocess communication primitive.
|
|
63
63
|
test_files:
|
64
64
|
- test/ichannel_class_test.rb
|
65
65
|
- test/setup.rb
|
66
|
+
has_rdoc:
|