iprocess 3.1.1 → 3.1.2
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.
- data/README.md +11 -13
- data/Rakefile +3 -5
- data/lib/iprocess/version.rb +1 -1
- data/lib/iprocess.rb +1 -1
- data/test/setup.rb +1 -5
- data/test/test_IProcess_class.rb +18 -19
- metadata +1 -1
data/README.md
CHANGED
@@ -10,21 +10,19 @@ __OVERVIEW__
|
|
10
10
|
|
11
11
|
__DESCRIPTION__
|
12
12
|
|
13
|
-
Provides a number of abstractions on top of spawning subprocesses and
|
14
|
-
communication. It has a simple and easy to use API that
|
15
|
-
asynchronous method calls plus one or two other
|
16
|
-
examples below.
|
13
|
+
Provides a number of abstractions on top of spawning subprocesses and
|
14
|
+
interprocess communication. It has a simple and easy to use API that
|
15
|
+
supports synchronous and asynchronous method calls plus one or two other
|
16
|
+
useful features shown in the examples below.
|
17
17
|
|
18
18
|
__EXAMPLES__
|
19
19
|
|
20
|
-
The first two examples(one & two) are using the synchronous APIs, a little below
|
21
|
-
those(3) demos the asynchronous API.
|
22
|
-
|
23
20
|
__1.__
|
24
21
|
|
25
|
-
Three subprocesses are spawned. The return value of the block, even though
|
26
|
-
in a subprocess, is returned to the parent process as long as it may
|
27
|
-
by Marshal(or the serializer of your choice, this is
|
22
|
+
Three subprocesses are spawned. The return value of the block, even though
|
23
|
+
executed in a subprocess, is returned to the parent process as long as it may
|
24
|
+
be serialized by Marshal(or the serializer of your choice, this is
|
25
|
+
configurable):
|
28
26
|
|
29
27
|
messages = IProcess.spawn(3) { {msg: "hello"} }
|
30
28
|
p messages # => [{msg: "hello"}, {msg: "hello"}, {msg: "hello"}]
|
@@ -44,11 +42,11 @@ try this:
|
|
44
42
|
@num + 1
|
45
43
|
end
|
46
44
|
end
|
47
|
-
IProcess.spawn
|
45
|
+
IProcess.spawn 5, Worker.new # => [2, 2, 2, 2, 2]
|
48
46
|
|
49
47
|
__3.__
|
50
48
|
|
51
|
-
A
|
49
|
+
A demo of how you would spawn two subprocesses asynchronously:
|
52
50
|
|
53
51
|
class Inbox
|
54
52
|
def initialize
|
@@ -60,7 +58,7 @@ A subprocess is spawned asynchronously.
|
|
60
58
|
end
|
61
59
|
end
|
62
60
|
inbox = Inbox.new
|
63
|
-
jobs = IProcess.spawn! { Process.pid }
|
61
|
+
jobs = IProcess.spawn!(2) { Process.pid }
|
64
62
|
jobs.map { |job| job.report_to(inbox) }
|
65
63
|
|
66
64
|
__SERIALIZERS__
|
data/Rakefile
CHANGED
data/lib/iprocess/version.rb
CHANGED
data/lib/iprocess.rb
CHANGED
data/test/setup.rb
CHANGED
data/test/test_IProcess_class.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
end
|
1
|
+
require_relative "setup"
|
2
|
+
class IProcessTest < Test::Unit::TestCase
|
3
|
+
def test_serializer_default_value
|
4
|
+
assert_equal Marshal, IProcess.serializer
|
5
|
+
end
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
:ok
|
13
|
-
end
|
14
|
-
end
|
7
|
+
def test_block_worker
|
8
|
+
messages = IProcess.spawn(2) { :hello }
|
9
|
+
assert_equal [:hello, :hello], messages
|
10
|
+
end
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def test_duck_typed_worker
|
13
|
+
messages = IProcess.spawn 2, worker.new
|
14
|
+
assert_equal [:hello, :hello], messages
|
19
15
|
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
17
|
+
private
|
18
|
+
def worker
|
19
|
+
Class.new do
|
20
|
+
def call
|
21
|
+
:hello
|
22
|
+
end
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|