iprocess 3.0.1 → 3.0.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 +29 -21
- data/iprocess.gemspec +1 -1
- data/lib/iprocess/version.rb +1 -1
- data/lib/iprocess.rb +3 -5
- metadata +4 -4
data/README.md
CHANGED
@@ -10,12 +10,12 @@ __OVERVIEW__
|
|
10
10
|
|
11
11
|
__DESCRIPTION__
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
IProcess makes InterProcess Communication(IPC) easy by providing a number of
|
14
|
+
abstractions on top of spawning subprocesses and interprocess communication.
|
15
|
+
It has a simple and easy to use API that supports synchronous and asynchronous
|
16
|
+
method calls plus a few other useful features that will become
|
17
|
+
obvious in the examples below. :-)
|
18
|
+
|
19
19
|
__EXAMPLES__
|
20
20
|
|
21
21
|
The first two examples(one & two) are using the synchronous APIs, a little below
|
@@ -23,15 +23,16 @@ those(3) demos the asynchronous API.
|
|
23
23
|
|
24
24
|
__1.__
|
25
25
|
|
26
|
-
A
|
26
|
+
A subprocess is spawned:
|
27
27
|
|
28
|
-
|
29
|
-
p
|
28
|
+
messages = IProcess.spawn { {msg: "hello"} }
|
29
|
+
p messages # => [{msg: "hello"}]
|
30
30
|
|
31
31
|
__2.__
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
You can spawn a subprocess with a block or with any object that responds to
|
34
|
+
`#call`. If you had a worker that was too complicated as a block you could
|
35
|
+
try this:
|
35
36
|
|
36
37
|
class Worker
|
37
38
|
def initialize
|
@@ -42,21 +43,24 @@ subprocesses you can spawn is variable (5, in this example):
|
|
42
43
|
@num + 1
|
43
44
|
end
|
44
45
|
end
|
45
|
-
|
46
46
|
IProcess.spawn(5, Worker.new) # => [2, 2, 2, 2, 2]
|
47
47
|
|
48
48
|
__3.__
|
49
49
|
|
50
|
-
A
|
51
|
-
When the subprocess completes, ':hi' is sent to `obj#recv` from another thread.
|
50
|
+
A subprocess is spawned asynchronously.
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
class Inbox
|
53
|
+
def initialize
|
54
|
+
@messages = []
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
def recv(msg)
|
58
|
+
@messages << msg
|
59
|
+
end
|
60
|
+
end
|
61
|
+
inbox = Inbox.new
|
62
|
+
jobs = IProcess.spawn! { Process.pid }
|
63
|
+
jobs.map { |job| job.report_to(inbox) }
|
60
64
|
|
61
65
|
|
62
66
|
__PLATFORM SUPPORT__
|
@@ -72,6 +76,10 @@ _unsupported_
|
|
72
76
|
* MacRuby
|
73
77
|
* JRuby
|
74
78
|
|
79
|
+
__LICENSE__
|
80
|
+
|
81
|
+
MIT. See LICENSE.txt.
|
82
|
+
|
75
83
|
__INSTALL__
|
76
84
|
|
77
|
-
gem install iprocess
|
85
|
+
$ gem install iprocess
|
data/iprocess.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.authors = ["Rob Gleeson"]
|
8
8
|
s.email = 'rob@flowof.info'
|
9
9
|
s.homepage = 'https://github.com/robgleeson/iprocess'
|
10
|
-
s.summary = '
|
10
|
+
s.summary = 'IProcess makes InterProcess Communication(IPC) easy.'
|
11
11
|
s.description = s.summary
|
12
12
|
|
13
13
|
s.files = `git ls-files`.each_line.map(&:chomp)
|
data/lib/iprocess/version.rb
CHANGED
data/lib/iprocess.rb
CHANGED
@@ -6,7 +6,7 @@ class IProcess
|
|
6
6
|
#
|
7
7
|
# @overload spawn(number_of = 1, worker)
|
8
8
|
#
|
9
|
-
# Spawn one or more
|
9
|
+
# Spawn one or more unit(s) of work.
|
10
10
|
#
|
11
11
|
# @param [Integer] number_of
|
12
12
|
# The number of subprocesses to spawn.
|
@@ -24,7 +24,7 @@ class IProcess
|
|
24
24
|
#
|
25
25
|
# @overload
|
26
26
|
#
|
27
|
-
# Spawn one or more
|
27
|
+
# Spawn one or more unit(s) of work asynchronously.
|
28
28
|
#
|
29
29
|
# @param
|
30
30
|
# (see IProcess.spawn)
|
@@ -38,7 +38,6 @@ class IProcess
|
|
38
38
|
|
39
39
|
def fork(number_of = 1, obj = nil, &worker)
|
40
40
|
worker = obj || worker
|
41
|
-
|
42
41
|
Array.new(number_of) do
|
43
42
|
IProcess.new(worker).tap { |job| job.execute }
|
44
43
|
end
|
@@ -51,7 +50,7 @@ class IProcess
|
|
51
50
|
# The unit of work to execute in a subprocess.
|
52
51
|
#
|
53
52
|
# @raise [ArgumentError]
|
54
|
-
# If a worker
|
53
|
+
# If a worker does not respond to _#call_.
|
55
54
|
#
|
56
55
|
# @return [IProcess]
|
57
56
|
# Returns self.
|
@@ -60,7 +59,6 @@ class IProcess
|
|
60
59
|
@worker = worker
|
61
60
|
@channel = nil
|
62
61
|
@pid = nil
|
63
|
-
|
64
62
|
unless @worker.respond_to?(:call)
|
65
63
|
raise ArgumentError,
|
66
64
|
"Expected worker to implement #{@worker.class}#call"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iprocess
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.2
|
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-
|
12
|
+
date: 2012-10-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 0.9.2
|
78
|
-
description:
|
78
|
+
description: IProcess makes InterProcess Communication(IPC) easy.
|
79
79
|
email: rob@flowof.info
|
80
80
|
executables: []
|
81
81
|
extensions: []
|
@@ -118,7 +118,7 @@ rubyforge_project: ! '[none]'
|
|
118
118
|
rubygems_version: 1.8.23
|
119
119
|
signing_key:
|
120
120
|
specification_version: 3
|
121
|
-
summary:
|
121
|
+
summary: IProcess makes InterProcess Communication(IPC) easy.
|
122
122
|
test_files:
|
123
123
|
- test/setup.rb
|
124
124
|
- test/test_IProcess_class.rb
|