ichannel 5.1.1.5 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ == v5.2.0
2
+ * add IChannel#last_msg.
3
+ Reads the last message written to the channel by reading until the channel
4
+ is empty. The last message is cached and reset to nil on call to #close.
5
+
1
6
  == v5.1.1.1, v5.1.1.2, v5.1.1.3, v5.1.1.4, v5.1.1.5
2
7
  * doc improvements
3
8
  a set of releases that improved the README & api docs.
data/README.md CHANGED
@@ -17,13 +17,11 @@ machine. All communication on a channel occurs on a streamed UNIXSocket that a
17
17
  channel uses to queues its messages (ruby objects), and also to ensure that
18
18
  messages are received in the order they are sent.
19
19
 
20
- __SERIALIZATION__
21
-
22
- ichannel relies on serialization when writing and reading from the underlying
23
- UNIXSocket. A ruby object is serialized before a write, and it is deserialized
24
- after a read. The choice of serializer is left up to you, though. A serializer
25
- can be any object that implements `dump` and `load` -- two methods that are
26
- usually implemented by serializers written in ruby.
20
+ Underneath the hood ruby objects are serialized when writing and reading from the
21
+ underlying UNIXSocket. A ruby object is serialized before a write, and it is
22
+ deserialized after a read. The choice of serializer is left up to you, though.
23
+ A serializer can be any object that implements `dump` and `load` -- two methods
24
+ that are usually implemented by serializers written in ruby.
27
25
 
28
26
  __EXAMPLES__
29
27
 
@@ -11,6 +11,7 @@ class IChannel
11
11
  def initialize(serializer)
12
12
  @reader, @writer = UNIXSocket.pair :STREAM
13
13
  @serializer = serializer
14
+ @last_msg = nil
14
15
  end
15
16
 
16
17
  #
@@ -31,6 +32,7 @@ class IChannel
31
32
  unless closed?
32
33
  @reader.close
33
34
  @writer.close
35
+ @last_msg = nil
34
36
  true
35
37
  end
36
38
  end
@@ -81,6 +83,20 @@ class IChannel
81
83
  end
82
84
  alias_method :put!, :write!
83
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
98
+ end
99
+
84
100
  #
85
101
  # Receive an object from the channel.
86
102
  #
@@ -1,3 +1,3 @@
1
1
  class IChannel
2
- VERSION = "5.1.1.5"
2
+ VERSION = "5.2.0"
3
3
  end
@@ -9,6 +9,26 @@ class IChannelTest < Test::Unit::TestCase
9
9
  @channel.close
10
10
  end
11
11
 
12
+ def test_last_msg
13
+ @channel.put %w(a)
14
+ @channel.put %w(b)
15
+ assert_equal %w(b), @channel.last_msg
16
+ end
17
+
18
+ def test_last_msg_cache
19
+ @channel.put %w(a)
20
+ 2.times { assert_equal %w(a), @channel.last_msg }
21
+ @channel.close
22
+ assert_equal nil, @channel.last_msg
23
+ end
24
+
25
+ def test_bust_last_msg_cache
26
+ @channel.put %w(a)
27
+ assert_equal %w(a), @channel.last_msg
28
+ @channel.put %w(b)
29
+ 2.times { assert_equal %w(b), @channel.last_msg }
30
+ end
31
+
12
32
  def test_put_and_get
13
33
  pid = fork do
14
34
  @channel.put %w(a b c)
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: 5.1.1.5
4
+ version: 5.2.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-03-21 00:00:00.000000000 Z
12
+ date: 2013-04-05 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "A modern and easy-to-use interprocess communication \n primitive."
15
15
  email:
@@ -46,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
46
46
  version: '0'
47
47
  segments:
48
48
  - 0
49
- hash: 718866409656378387
49
+ hash: 1696570348195705541
50
50
  required_rubygems_version: !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  version: '0'
56
56
  segments:
57
57
  - 0
58
- hash: 718866409656378387
58
+ hash: 1696570348195705541
59
59
  requirements: []
60
60
  rubyforge_project:
61
61
  rubygems_version: 1.8.23