em-rocketio-linda-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 98dfdf7000ed33fed66fef953dee21449acf8815
4
- data.tar.gz: a31dfc4320438cc867428cdf697b57500f54a7d6
3
+ metadata.gz: 0484939a37aaa0a93cd380fea16785a5e99fc6a2
4
+ data.tar.gz: b6bcde795bfc5303fd6b3076135d5f8c3c262b28
5
5
  SHA512:
6
- metadata.gz: c9321a9e566c9e232d72b59de669038a8273d6f74b1b6f49af986559d303a41d9a2cf5f1fe1e18b20aec0462a67d9f813784eaa4991311ed95c2918293db3c92
7
- data.tar.gz: 6a33d796dc72c353629baf72c081c6d0f89e4e6e2be4b78485781cc8d1738a7d0658503d14dd471cba79f6f92bb8cf9ba35cfb12abf3b82634d641305cd9a7f5
6
+ metadata.gz: 80ab851054515b3abce7c1e92cdf51b9f1fa558e52cfe9f0db9dee8406a1422c7a39e7316f7f7207646e740d6787377e3a38b5d7d8fc2bf66d8b41e868d3f225
7
+ data.tar.gz: a37de55934601f876eed60253a25ffc7dd48af85343fcf5721c02f20c360bff1a0dcf1bc22a2b63bbef5dd414553030c5a556653a60ab242a22e02e33108dfa6
data/.gitignore CHANGED
@@ -1,3 +1,6 @@
1
+ *~
2
+ *#*
3
+ .DS_Store
1
4
  *.gem
2
5
  *.rbc
3
6
  .bundle
@@ -1,3 +1,7 @@
1
+ === 0.0.3 2013-07-04
2
+
3
+ * blocking style TupleSpace#read and TupleSpace#take
4
+
1
5
  === 0.0.2 2013-05-29
2
6
 
3
7
  * bugfix callback_id duplication in client lib
data/README.md CHANGED
@@ -62,11 +62,11 @@ start server
62
62
 
63
63
  % export PORT=5000
64
64
  % export WS_PORT=9000
65
- % rake test_server
65
+ % bundle exec rake test_server
66
66
 
67
67
  run test
68
68
 
69
- % rake test
69
+ % bundle exec rake test
70
70
 
71
71
 
72
72
  Contributing
@@ -39,8 +39,20 @@ module EM
39
39
  raise ArgumentError, "tuple must be Array or Hash"
40
40
  end
41
41
  callback_id = "#{Time.now.to_i}#{Time.now.usec}_#{rand(1000000).to_i}"
42
- @linda.io.once "__linda_read_callback_#{callback_id}", &block
42
+ if block_given?
43
+ @linda.io.once "__linda_read_callback_#{callback_id}", &block
44
+ @linda.io.push "__linda_read", [@name, tuple, callback_id]
45
+ return
46
+ end
47
+ result_tuple = nil
48
+ @linda.io.once "__linda_read_callback_#{callback_id}" do |tuple|
49
+ result_tuple = tuple
50
+ end
43
51
  @linda.io.push "__linda_read", [@name, tuple, callback_id]
52
+ while !result_tuple do
53
+ sleep 0.1
54
+ end
55
+ return result_tuple
44
56
  end
45
57
 
46
58
  def take(tuple, &block)
@@ -48,8 +60,20 @@ module EM
48
60
  raise ArgumentError, "tuple must be Array or Hash"
49
61
  end
50
62
  callback_id = "#{Time.now.to_i}#{Time.now.usec}_#{rand(1000000).to_i}"
51
- @linda.io.once "__linda_take_callback_#{callback_id}", &block
63
+ if block_given?
64
+ @linda.io.once "__linda_take_callback_#{callback_id}", &block
65
+ @linda.io.push "__linda_take", [@name, tuple, callback_id]
66
+ return
67
+ end
68
+ result_tuple = nil
69
+ @linda.io.once "__linda_take_callback_#{callback_id}" do |tuple|
70
+ result_tuple = tuple
71
+ end
52
72
  @linda.io.push "__linda_take", [@name, tuple, callback_id]
73
+ while !result_tuple do
74
+ sleep 0.1
75
+ end
76
+ return result_tuple
53
77
  end
54
78
 
55
79
  def watch(tuple, &block)
@@ -2,7 +2,7 @@ module EM
2
2
  module RocketIO
3
3
  module Linda
4
4
  class Client
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.3"
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ $:.unshift File.expand_path '../lib', File.dirname(__FILE__)
4
+ require 'em-rocketio-linda-client'
5
+
6
+ EM::run do
7
+ client = EM::RocketIO::Linda::Client.new "http://linda.shokai.org"
8
+ ts = client.tuplespace["test_spae"]
9
+
10
+ client.io.on :connect do
11
+ puts "connect #{client.io.type} (#{client.io.session})"
12
+ ts.write [1,2,3]
13
+ ts.write [1,2,3,4]
14
+ ts.write [1,2,3,4,"abc"]
15
+
16
+ EM::defer do
17
+ loop do
18
+ tuple = ts.take [1,2]
19
+ puts "blocking take #{tuple}"
20
+ end
21
+ end
22
+
23
+ EM::add_periodic_timer 1 do
24
+ ts.write [1,2, Time.now]
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,73 @@
1
+ require File.expand_path 'test_helper', File.dirname(__FILE__)
2
+
3
+ class TestBlockingReadTake < MiniTest::Test
4
+
5
+ def test_blocking_take
6
+ ts_name = "ts_blocking_take_#{rand Time.now.to_i}"
7
+ results = Array.new
8
+
9
+ EM::run do
10
+ client = EM::RocketIO::Linda::Client.new App.url
11
+ ts = client.tuplespace[ts_name]
12
+
13
+ client.io.on :connect do
14
+ 1.upto(3) do |i|
15
+ ts.write ["blocking", "take", i]
16
+ end
17
+
18
+ client2 = EM::RocketIO::Linda::Client.new App.url
19
+ ts2 = client2.tuplespace[ts_name]
20
+ client2.io.on :connect do
21
+ EM::defer do
22
+ loop do
23
+ results.push ts2.take ["blocking", "take"]
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ EM::defer do
30
+ 50.times do
31
+ sleep 0.1
32
+ break if results.size > 2
33
+ end
34
+ EM::add_timer 1 do
35
+ EM::stop
36
+ end
37
+ end
38
+ end
39
+
40
+ assert_equal results.size, 3
41
+ assert_equal results.shift, ["blocking", "take", 3]
42
+ assert_equal results.shift, ["blocking", "take", 2]
43
+ assert_equal results.shift, ["blocking", "take", 1]
44
+ end
45
+
46
+
47
+ def test_blocking_read
48
+ ts_name = "ts_blocking_read_#{rand Time.now.to_i}"
49
+ results = Array.new
50
+
51
+ EM::run do
52
+ client = EM::RocketIO::Linda::Client.new App.url
53
+ ts = client.tuplespace[ts_name]
54
+ client.io.on :connect do
55
+ EM::defer do
56
+ 1.upto(3) do |i|
57
+ ts.write ["blocking", "read", i]
58
+ results.push ts.read ["blocking", "read"]
59
+ end
60
+ EM::add_timer 1 do
61
+ EM::stop
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ assert_equal results.size, 3
68
+ assert_equal results.shift, ["blocking", "read", 1]
69
+ assert_equal results.shift, ["blocking", "read", 2]
70
+ assert_equal results.shift, ["blocking", "read", 3]
71
+ end
72
+
73
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-rocketio-linda-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sho Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-29 00:00:00.000000000 Z
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -140,9 +140,11 @@ files:
140
140
  - lib/em-rocketio-linda-client/client.rb
141
141
  - lib/em-rocketio-linda-client/version.rb
142
142
  - sample/sample.rb
143
+ - sample/sample_blocking.rb
143
144
  - test/app.rb
144
145
  - test/app/config.ru
145
146
  - test/app/main.rb
147
+ - test/test_blocking_read_take.rb
146
148
  - test/test_client_disconnect.rb
147
149
  - test/test_em_rocketio_linda_client.rb
148
150
  - test/test_helper.rb
@@ -174,7 +176,7 @@ test_files:
174
176
  - test/app.rb
175
177
  - test/app/config.ru
176
178
  - test/app/main.rb
179
+ - test/test_blocking_read_take.rb
177
180
  - test/test_client_disconnect.rb
178
181
  - test/test_em_rocketio_linda_client.rb
179
182
  - test/test_helper.rb
180
- has_rdoc: