em-nodes 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fe922a1ce046c59c80d0e07fef0231bf5fa01e61
4
+ data.tar.gz: 1779d2eae2c85475290ff25dd6c885da0bffc3df
5
+ SHA512:
6
+ metadata.gz: b654c62869647ee287a5b5e15627020ef2512aafa72db19d18e9eb13e9f8260bbd1959449e5af292fb65e290835b45cab86299edbd1cd743b8e3898805b531d3
7
+ data.tar.gz: 571c7a47c76818db7fabfd20c106290bdf6237937da0e5e97d6538e34aaefdcaf34313cfd2706dd75ed20fa21e02364a4985f184d5a87f43ae7314037c835fce
@@ -0,0 +1,22 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+ require 'logger'
4
+
5
+ l = Logger.new(STDOUT)
6
+ l.level = Logger::INFO
7
+ EM::Nodes.logger = l
8
+
9
+ class Client < EM::Nodes::DefaultClient
10
+ def info
11
+ { :name => "client" }
12
+ end
13
+
14
+ def on_task(task_id, x)
15
+ new_x = x + 1
16
+ send_task_result(task_id, new_x)
17
+ end
18
+ end
19
+
20
+ EM.run do
21
+ Client.connect "/tmp/em_nodes_test.sock"
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'bundler/setup'
2
+ Bundler.require
3
+ require 'logger'
4
+
5
+ l = Logger.new(STDOUT)
6
+ l.level = Logger::INFO
7
+ EM::Nodes.logger = l
8
+
9
+ class Server < EM::Nodes::DefaultServer
10
+ def on_task_result(new_x)
11
+ puts new_x
12
+ EM.stop
13
+ end
14
+ end
15
+
16
+ EM.run do
17
+ Server.start "/tmp/em_nodes_test.sock"
18
+
19
+ Thread.new do
20
+ puts "waiting for first client"
21
+ sleep 0.5 while Server.ready_clients.count < 1
22
+
23
+ Server.ready_clients.first.send_task(0)
24
+ end
25
+ end
@@ -3,16 +3,23 @@ class EM::Nodes::Client
3
3
 
4
4
  def on_task(task_id, data)
5
5
  # redefine me
6
+ # after task done, should call send_task_result(task_id, result)
6
7
  end
7
8
 
8
- private
9
-
10
- def on_task_internal(task_id, data)
11
- on_task(task_id, data)
9
+ def tasks
10
+ @tasks ||= {}
12
11
  end
13
12
 
14
13
  def send_task_result(task_id, result)
15
14
  send_task_result_internal(task_id, result)
15
+ tasks.delete(task_id)
16
+ end
17
+
18
+ private
19
+
20
+ def on_task_internal(task_id, data)
21
+ obj = on_task(task_id, data)
22
+ tasks[task_id] = obj
16
23
  end
17
24
  end
18
25
  end
@@ -2,5 +2,5 @@ module EventMachine
2
2
  end
3
3
 
4
4
  module EventMachine::Nodes
5
- VERSION = "0.2.3"
5
+ VERSION = "0.2.4"
6
6
  end
data/spec/task_spec.rb CHANGED
@@ -34,9 +34,10 @@ describe "Task spec" do
34
34
  client4 = nil
35
35
  EM.run do
36
36
  $server4 = Server4.start('127.0.0.1', 19995)
37
+ sleep 0.1
37
38
  $client4 = Client4.connect('127.0.0.1', 19995)
38
39
 
39
- EM.next_tick do
40
+ EM.add_timer(0.1) do
40
41
  client4 = Server4.clients.first
41
42
  10.times { |i| client4.send_task(i) }
42
43
  end
@@ -52,7 +53,7 @@ describe "Task spec" do
52
53
  $server4 = Server4.start('127.0.0.1', 19996)
53
54
  $client4 = Client4.connect('127.0.0.1', 19996)
54
55
 
55
- EM.next_tick do
56
+ EM.add_timer(0.1) do
56
57
  client4 = Server4.clients.first
57
58
  20.times { |i| client4.send_task(i) }
58
59
  end
@@ -0,0 +1,55 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class Waiter
4
+ attr_accessor :time
5
+ def initialize(conn, task_id)
6
+ @time = Time.now
7
+ EM.add_timer(1) { conn.send_task_result(task_id, true) }
8
+ end
9
+ end
10
+
11
+ class Client5 < EM::Nodes::Client
12
+ include TaskFeature
13
+
14
+ def on_task(task_id, data)
15
+ Waiter.new(self, task_id)
16
+ end
17
+ end
18
+
19
+
20
+ class Server5 < EM::Nodes::Server
21
+ include TaskFeature
22
+
23
+ def on_task_result(res)
24
+ $server5_results << res
25
+ EM.stop if $server5_results.size == 10
26
+ end
27
+ end
28
+
29
+ describe "write task object, to prevent GC" do
30
+ before {
31
+ $server5_results = []
32
+ }
33
+
34
+ it "should work" do
35
+ client5 = nil
36
+ EM.run do
37
+ $server5 = Server5.start('127.0.0.1', 19997)
38
+ $client5 = Client5.connect('127.0.0.1', 19997)
39
+
40
+ EM.add_timer(0.1) do
41
+ client5 = Server5.clients.first
42
+ 10.times { |i| client5.send_task(i) }
43
+ end
44
+
45
+ EM.add_timer(0.5) do
46
+ $server5_results.should be_empty
47
+ $client5.tasks.size.should == 10
48
+ $client5.tasks.values.map(&:time).compact.size.should == 10
49
+ end
50
+ end
51
+
52
+ $server5_results.size.should == 10
53
+ $client5.tasks.size.should == 0
54
+ end
55
+ end
metadata CHANGED
@@ -1,92 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: em-nodes
3
- version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 3
10
- version: 0.2.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.4
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - "'Konstantin Makarchev'"
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2014-05-29 00:00:00 +04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- prerelease: false
23
- version_requirements: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 3
29
- segments:
30
- - 0
31
- version: "0"
32
- requirement: *id001
11
+ date: 2015-06-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
33
14
  name: eventmachine
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
34
20
  type: :runtime
35
- - !ruby/object:Gem::Dependency
36
21
  prerelease: false
37
- version_requirements: &id002 !ruby/object:Gem::Requirement
38
- none: false
39
- requirements:
40
- - - ~>
41
- - !ruby/object:Gem::Version
42
- hash: 5
43
- segments:
44
- - 1
45
- - 5
46
- version: "1.5"
47
- requirement: *id002
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
48
28
  name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
49
34
  type: :development
50
- - !ruby/object:Gem::Dependency
51
35
  prerelease: false
52
- version_requirements: &id003 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
- version: "0"
61
- requirement: *id003
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
62
42
  name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
63
48
  type: :development
64
- - !ruby/object:Gem::Dependency
65
49
  prerelease: false
66
- version_requirements: &id004 !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
69
52
  - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
75
- requirement: *id004
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
76
56
  name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
77
62
  type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
78
69
  description: Simple EM client server, and some stuffs
79
- email:
70
+ email:
80
71
  - "'kostya27@gmail.com'"
81
72
  executables: []
82
-
83
73
  extensions: []
84
-
85
74
  extra_rdoc_files: []
86
-
87
- files:
88
- - .gitignore
89
- - .rspec
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
90
78
  - Gemfile
91
79
  - LICENSE.txt
92
80
  - README.md
@@ -100,6 +88,8 @@ files:
100
88
  - em-nodes.gemspec
101
89
  - examples/chat_client.rb
102
90
  - examples/chat_server.rb
91
+ - examples/work_client.rb
92
+ - examples/work_server.rb
103
93
  - lib/em-nodes.rb
104
94
  - lib/em-nodes/adapter.rb
105
95
  - lib/em-nodes/client.rb
@@ -119,44 +109,36 @@ files:
119
109
  - spec/simple_spec.rb
120
110
  - spec/spec_helper.rb
121
111
  - spec/task_spec.rb
122
- has_rdoc: true
112
+ - spec/waiter_spec.rb
123
113
  homepage: https://github.com/kostya/em-nodes
124
- licenses:
114
+ licenses:
125
115
  - MIT
116
+ metadata: {}
126
117
  post_install_message:
127
118
  rdoc_options: []
128
-
129
- require_paths:
119
+ require_paths:
130
120
  - lib
131
- required_ruby_version: !ruby/object:Gem::Requirement
132
- none: false
133
- requirements:
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
134
123
  - - ">="
135
- - !ruby/object:Gem::Version
136
- hash: 3
137
- segments:
138
- - 0
139
- version: "0"
140
- required_rubygems_version: !ruby/object:Gem::Requirement
141
- none: false
142
- requirements:
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
143
128
  - - ">="
144
- - !ruby/object:Gem::Version
145
- hash: 3
146
- segments:
147
- - 0
148
- version: "0"
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
149
131
  requirements: []
150
-
151
132
  rubyforge_project:
152
- rubygems_version: 1.4.2
133
+ rubygems_version: 2.2.2
153
134
  signing_key:
154
- specification_version: 3
135
+ specification_version: 4
155
136
  summary: Simple EM client server, and some stuffs
156
- test_files:
137
+ test_files:
157
138
  - spec/base_spec.rb
158
139
  - spec/hello_spec.rb
159
140
  - spec/simple2_spec.rb
160
141
  - spec/simple_spec.rb
161
142
  - spec/spec_helper.rb
162
143
  - spec/task_spec.rb
144
+ - spec/waiter_spec.rb