iprocess 3.0.1 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -10,12 +10,12 @@ __OVERVIEW__
10
10
 
11
11
  __DESCRIPTION__
12
12
 
13
- The purpose of IProcess is to allow you, the developer, run units of work
14
- in parallel to each other. If you were to get down to implementation details
15
- you'd see I'm using Kernel#fork to spawn subproccesses that dispatch a unit of
16
- work. As a bonus the parent process can collect the return value of each unit
17
- of work as long as it is serializable (i.e: Marshal can dump & load it).
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 single subprocess is spawned:
26
+ A subprocess is spawned:
27
27
 
28
- message = IProcess.spawn { [:yes, :no] }
29
- p message # => [[:yes, :no]]
28
+ messages = IProcess.spawn { {msg: "hello"} }
29
+ p messages # => [{msg: "hello"}]
30
30
 
31
31
  __2.__
32
32
 
33
- A unit of work does not need to be a block, though, and the number of
34
- subprocesses you can spawn is variable (5, in this example):
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 single subprocess is spawned asynchronously.
51
- When the subprocess completes, ':hi' is sent to `obj#recv` from another thread.
50
+ A subprocess is spawned asynchronously.
52
51
 
53
- obj = Object.new
54
- def obj.recv(msg)
55
- msg.to_s.capitalize!
56
- end
52
+ class Inbox
53
+ def initialize
54
+ @messages = []
55
+ end
57
56
 
58
- jobs = IProcess.spawn! { :hi }
59
- jobs.map { |job| job.report_to(obj) }
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 = 'Transport Ruby objects between processes on UNIX-like operating systems'
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)
@@ -1,3 +1,3 @@
1
1
  class IProcess
2
- VERSION = '3.0.1'
2
+ VERSION = '3.0.2'
3
3
  end
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 subprocesses.
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 subprocesses asynchronously.
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 is not given.
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.1
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-09-26 00:00:00.000000000 Z
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: Transport Ruby objects between processes on UNIX-like operating systems
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: Transport Ruby objects between processes on UNIX-like operating systems
121
+ summary: IProcess makes InterProcess Communication(IPC) easy.
122
122
  test_files:
123
123
  - test/setup.rb
124
124
  - test/test_IProcess_class.rb