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 CHANGED
@@ -1,4 +1,4 @@
1
1
  -m markdown -M redcarpet
2
- --
2
+ -
3
3
  README.md
4
4
  LICENSE.txt
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
1
  source 'http://rubygems.org'
2
- gem 'rake'
2
+ group :development do
3
+ gem 'rake'
4
+ gem 'redcarpet'
5
+ gem 'yard'
6
+ end
3
7
  gemspec
@@ -25,8 +25,10 @@ class IChannel
25
25
  # Returns nil when the channel is already closed.
26
26
  #
27
27
  def close
28
- if !@reader.closed? && !@writer.closed?
29
- !! [@reader.close, @writer.close]
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
- if @writer.closed?
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 {#put}, which waits indefinitely until the channel becomes writable,
55
- # this method will raise an IOError if 0.1 seconds elapse and the channel
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
- # @raise [IOError]
59
- # When 0.1 seconds elapse and the channel remains unwritable.
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
- # @param (see IChannel#put).
64
+ # @raise [IOError]
65
+ # When _timeout_ seconds elapse & the channel remains unwritable.
62
66
  #
63
- def write!(object)
64
- _, writable, _ = IO.select [], [@writer], [], 0.1
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(@object), 0
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 a object from the channel.
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
- if @reader.closed?
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 a object from the channel.
95
+ # Receive an object from the channel.
94
96
  #
95
- # Unlike {#get}, which waits indefinitely until the channel becomes readable,
96
- # this method will raise an IOError if 0.1 seconds elapse and the channel
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
- # When 0.1 seconds elapse and the channel remains unreadable.
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
- readble, _ = IO.select [@reader], [], [], 0.1
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
@@ -1,3 +1,3 @@
1
1
  class IChannel
2
- VERSION = "3.0.2"
2
+ VERSION = "3.0.3"
3
3
  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: 3.0.2
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-17 00:00:00.000000000 Z
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: 4054372097139346221
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: 4054372097139346221
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: