ichannel 8.0.0 → 8.1.0

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.
@@ -1,3 +1,7 @@
1
+ == v8.1.0
2
+ - add Redis#{unix_socket,redis?}, UNIXSocket#{unix_socket?, redis?}
3
+ Predicates indicating if you have a redis or unix socket channel.
4
+
1
5
  == v8.0.0
2
6
  - Redis#write! does not time out.
3
7
  A write to redis is not wrapped in Timeout.timeout() anymore
@@ -7,8 +11,8 @@
7
11
  Redis#get!, UNIXSocket#get!, UNIXSocket#write! raise
8
12
  IChannel::TimeoutError instead of Timeout::Error.
9
13
 
10
- - Remove all use of timeout.rb from lib/
11
- 'timeout' from the standard library is retired from ichannel.
14
+ - Remove use of timeout.rb from lib/
15
+ retire 'timeout.rb' from stdlib
12
16
 
13
17
  == v7.1.0
14
18
  - Redis#last_msg, UNIXSocket#last_msg return last read value
data/README.md CHANGED
@@ -115,8 +115,10 @@ And to finish:
115
115
 
116
116
  __SEE ALSO__
117
117
 
118
- - [ifuture](https://github.com/Havenwood/ifuture)
119
- futures built on process forks and ichannel.
118
+ - [ifuture](https://github.com/havenwood/ifuture)
119
+ An implementation of the future pattern that leverages
120
+ `Kernel#fork` and ichannel.
121
+ credit [@havenwood](https://github.com/havenwood).
120
122
 
121
123
  __LICENSE__
122
124
 
@@ -144,4 +144,24 @@ class IChannel::Redis
144
144
  def readable?
145
145
  !closed? && !empty?
146
146
  end
147
+
148
+ #
149
+ # @return [Boolean]
150
+ # Returns false.
151
+ #
152
+ # @see UNIXSocket#unix_socket?
153
+ #
154
+ def unix_socket?
155
+ false
156
+ end
157
+
158
+ #
159
+ # @return [Boolean]
160
+ # Returns true.
161
+ #
162
+ # @see UNIXSocket#redis?
163
+ #
164
+ def redis?
165
+ true
166
+ end
147
167
  end
@@ -1,160 +1,178 @@
1
1
  require 'socket'
2
- module IChannel
3
- class UNIXSocket
4
- SEP = '_$_'
5
- if respond_to? :private_constant
6
- private_constant :SEP
7
- end
2
+ class IChannel::UNIXSocket
3
+ SEP = '_$_'
4
+ if respond_to? :private_constant
5
+ private_constant :SEP
6
+ end
8
7
 
9
- #
10
- # @param [#dump,#load] serializer
11
- # Any object that implements dump, & load.
12
- #
13
- # @return [IChannel::UNIXSocket]
14
- #
15
- def initialize(serializer = Marshal, adapter_options)
16
- @serializer = serializer
17
- @last_msg = nil
18
- @reader, @writer = ::UNIXSocket.pair :STREAM
19
- end
8
+ #
9
+ # @param [#dump,#load] serializer
10
+ # Any object that implements dump, & load.
11
+ #
12
+ # @return [IChannel::UNIXSocket]
13
+ #
14
+ def initialize(serializer = Marshal, adapter_options)
15
+ @serializer = serializer
16
+ @last_msg = nil
17
+ @reader, @writer = ::UNIXSocket.pair :STREAM
18
+ end
20
19
 
21
- #
22
- # @return [Boolean]
23
- # Returns true when the channel is closed.
24
- #
25
- def closed?
26
- @reader.closed? && @writer.closed?
27
- end
20
+ #
21
+ # @return [Boolean]
22
+ # Returns true when the channel is closed.
23
+ #
24
+ def closed?
25
+ @reader.closed? && @writer.closed?
26
+ end
28
27
 
29
- #
30
- # Close the channel.
31
- #
32
- # @return [Boolean]
33
- # Returns true when the channel has been closed.
34
- #
35
- def close
36
- unless closed?
37
- @reader.close
38
- @writer.close
39
- true
40
- end
28
+ #
29
+ # Close the channel.
30
+ #
31
+ # @return [Boolean]
32
+ # Returns true when the channel has been closed.
33
+ #
34
+ def close
35
+ unless closed?
36
+ @reader.close
37
+ @writer.close
38
+ true
41
39
  end
40
+ end
42
41
 
43
- #
44
- # Add an object to the channel.
45
- #
46
- # @raise [IOError]
47
- # When the channel is closed.
48
- #
49
- # @param [Object] object
50
- # An object to add.
51
- #
52
- def write(object)
53
- write!(object, nil)
54
- end
55
- alias_method :put, :write
42
+ #
43
+ # Add an object to the channel.
44
+ #
45
+ # @raise [IOError]
46
+ # When the channel is closed.
47
+ #
48
+ # @param [Object] object
49
+ # An object to add.
50
+ #
51
+ def write(object)
52
+ write!(object, nil)
53
+ end
54
+ alias_method :put, :write
56
55
 
57
- #
58
- # Add an object to the channel.
59
- #
60
- # @param
61
- # (see IChannel#write)
62
- #
63
- # @param [Numeric] timeout
64
- # The number of seconds to wait for the channel to become writable.
65
- #
66
- # @raise
67
- # (see IChannel#write)
68
- #
69
- # @raise [IOError]
70
- # When _timeout_ seconds elapse and the channel cannot be written to.
71
- #
72
- def write!(object, timeout = 0.1)
73
- if @writer.closed?
74
- raise IOError, 'The channel cannot be written to (closed).'
75
- end
76
- _, writable, _ = IO.select nil, [@writer], nil, timeout
77
- if writable
78
- msg = @serializer.dump(object)
79
- writable[0].syswrite "#{msg}#{SEP}"
80
- else
81
- raise IOError, 'The channel cannot be written to.'
82
- end
56
+ #
57
+ # Add an object to the channel.
58
+ #
59
+ # @param
60
+ # (see IChannel#write)
61
+ #
62
+ # @param [Numeric] timeout
63
+ # The number of seconds to wait for the channel to become writable.
64
+ #
65
+ # @raise
66
+ # (see IChannel#write)
67
+ #
68
+ # @raise [IOError]
69
+ # When _timeout_ seconds elapse and the channel cannot be written to.
70
+ #
71
+ def write!(object, timeout = 0.1)
72
+ if @writer.closed?
73
+ raise IOError, 'The channel cannot be written to (closed).'
83
74
  end
84
- alias_method :put!, :write!
85
-
86
- #
87
- # Reads the last message written to the channel by reading until the channel
88
- # is empty. The last message is cached and reset to nil on call to {#close}.
89
- #
90
- # @return [Object]
91
- # Returns the last message to be written to the channel.
92
- #
93
- def last_msg
94
- while readable?
95
- @last_msg = get
96
- end
97
- @last_msg
75
+ _, writable, _ = IO.select nil, [@writer], nil, timeout
76
+ if writable
77
+ msg = @serializer.dump(object)
78
+ writable[0].syswrite "#{msg}#{SEP}"
79
+ else
80
+ raise IOError, 'The channel cannot be written to.'
98
81
  end
82
+ end
83
+ alias_method :put!, :write!
99
84
 
100
- #
101
- # Receive an object from the channel.
102
- #
103
- # @raise [IOError]
104
- # When the channel is closed.
105
- #
106
- # @return [Object]
107
- # The object read from the channel.
108
- #
109
- def recv
110
- recv!(nil)
85
+ #
86
+ # Reads the last message written to the channel by reading until the channel
87
+ # is empty. The last message is cached and reset to nil on call to {#close}.
88
+ #
89
+ # @return [Object]
90
+ # Returns the last message to be written to the channel.
91
+ #
92
+ def last_msg
93
+ while readable?
94
+ @last_msg = get
111
95
  end
112
- alias_method :get, :recv
96
+ @last_msg
97
+ end
113
98
 
114
- #
115
- # Receive an object from the channel.
116
- #
117
- # Unlike {#recv}, which waits indefinitely until the channel becomes readable,
118
- # this method will raise an IOError when _timeout_ seconds elapse and the
119
- # channel remains unreadable.
120
- #
121
- # @param [Numeric] timeout
122
- # The number of seconds to wait for the channel to become readable.
123
- #
124
- # @raise [IOError]
125
- # (see IChannel#recv)
126
- #
127
- # @raise [IChannel::TimeoutError]
128
- # When _timeout_ seconds elapse & the channel remains unreadable.
129
- #
130
- # @return [Object]
131
- # The object read from the channel.
132
- #
133
- def recv!(timeout = 0.1)
134
- if @reader.closed?
135
- raise IOError, 'The channel cannot be read from (closed).'
136
- end
137
- readable, _ = IO.select [@reader], nil, nil, timeout
138
- if readable
139
- msg = readable[0].readline(SEP).chomp SEP
140
- @last_msg = @serializer.load msg
141
- else
142
- raise IChannel::TimeoutError, 'Time out on read (waited for %s second(s))' % [timeout]
143
- end
99
+ #
100
+ # Receive an object from the channel.
101
+ #
102
+ # @raise [IOError]
103
+ # When the channel is closed.
104
+ #
105
+ # @return [Object]
106
+ # The object read from the channel.
107
+ #
108
+ def recv
109
+ recv!(nil)
110
+ end
111
+ alias_method :get, :recv
112
+
113
+ #
114
+ # Receive an object from the channel.
115
+ #
116
+ # Unlike {#recv}, which waits indefinitely until the channel becomes readable,
117
+ # this method will raise an IOError when _timeout_ seconds elapse and the
118
+ # channel remains unreadable.
119
+ #
120
+ # @param [Numeric] timeout
121
+ # The number of seconds to wait for the channel to become readable.
122
+ #
123
+ # @raise [IOError]
124
+ # (see IChannel#recv)
125
+ #
126
+ # @raise [IChannel::TimeoutError]
127
+ # When _timeout_ seconds elapse & the channel remains unreadable.
128
+ #
129
+ # @return [Object]
130
+ # The object read from the channel.
131
+ #
132
+ def recv!(timeout = 0.1)
133
+ if @reader.closed?
134
+ raise IOError, 'The channel cannot be read from (closed).'
135
+ end
136
+ readable, _ = IO.select [@reader], nil, nil, timeout
137
+ if readable
138
+ msg = readable[0].readline(SEP).chomp SEP
139
+ @last_msg = @serializer.load msg
140
+ else
141
+ raise IChannel::TimeoutError, 'Time out on read (waited for %s second(s))' % [timeout]
144
142
  end
145
- alias_method :get!, :recv!
143
+ end
144
+ alias_method :get!, :recv!
146
145
 
147
- #
148
- # @return [Boolean]
149
- # Returns true when the channel is readable.
150
- #
151
- def readable?
152
- if closed?
153
- false
154
- else
155
- readable, _ = IO.select [@reader], nil, nil, 0
156
- !! readable
157
- end
146
+ #
147
+ # @return [Boolean]
148
+ # Returns true when the channel is readable.
149
+ #
150
+ def readable?
151
+ if closed?
152
+ false
153
+ else
154
+ readable, _ = IO.select [@reader], nil, nil, 0
155
+ !! readable
158
156
  end
159
157
  end
158
+
159
+ #
160
+ # @return [Boolean]
161
+ # Returns true.
162
+ #
163
+ # @see Redis#unix_socket?
164
+ #
165
+ def unix_socket?
166
+ true
167
+ end
168
+
169
+ #
170
+ # @return [Boolean]
171
+ # Returns false.
172
+ #
173
+ # @see Redis#redis?
174
+ #
175
+ def redis?
176
+ false
177
+ end
160
178
  end
@@ -1,3 +1,3 @@
1
1
  module IChannel
2
- VERSION = "8.0.0"
2
+ VERSION = "8.1.0"
3
3
  end
@@ -0,0 +1,3 @@
1
+ bump in lib/ichannel/version.rb
2
+ bump in ChangeLog.txt
3
+ bundle exec rake release
@@ -22,4 +22,12 @@ class IChannelRedisTest < testcase
22
22
  @channel.instance_variable_get(:@redis).del(key)
23
23
  @channel.close
24
24
  end
25
+
26
+ def test_redis?
27
+ assert_equal true, @channel.redis?
28
+ end
29
+
30
+ def test_unix_socket?
31
+ assert_equal false, @channel.unix_socket?
32
+ end
25
33
  end
@@ -12,4 +12,12 @@ class IChannelTest < Test::Unit::TestCase
12
12
  def teardown
13
13
  @channel.close
14
14
  end
15
+
16
+ def test_redis?
17
+ assert_equal false, @channel.redis?
18
+ end
19
+
20
+ def test_unix_socket?
21
+ assert_equal true, @channel.unix_socket?
22
+ end
15
23
  end
@@ -17,7 +17,9 @@ module UniformIChannelTest
17
17
  put
18
18
  put!
19
19
  recv
20
- recv!).each do |method|
20
+ recv!
21
+ unix_socket?
22
+ redis?).each do |method|
21
23
  assert @channel.respond_to? method
22
24
  end
23
25
  end
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: 8.0.0
4
+ version: 8.1.0
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: 2013-08-15 00:00:00.000000000 Z
12
+ date: 2013-08-20 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: interprocess communication channel
15
15
  email:
@@ -34,6 +34,7 @@ files:
34
34
  - lib/ichannel/redis.rb
35
35
  - lib/ichannel/unix_socket.rb
36
36
  - lib/ichannel/version.rb
37
+ - release-notes.txt
37
38
  - test/ichannel_redis_test.rb
38
39
  - test/ichannel_unix_test.rb
39
40
  - test/setup.rb
@@ -52,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
52
53
  version: '0'
53
54
  segments:
54
55
  - 0
55
- hash: 3456216786864862770
56
+ hash: -1427294118300470678
56
57
  required_rubygems_version: !ruby/object:Gem::Requirement
57
58
  none: false
58
59
  requirements:
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  version: '0'
62
63
  segments:
63
64
  - 0
64
- hash: 3456216786864862770
65
+ hash: -1427294118300470678
65
66
  requirements: []
66
67
  rubyforge_project:
67
68
  rubygems_version: 1.8.23