iprocess 5.1.3 → 6.0.0

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/ChangeLog.txt ADDED
@@ -0,0 +1,9 @@
1
+ = v6.0.0
2
+ - Tidy up the test suite
3
+ Not a lot to say about that :-) The suite is smaller, so I've defined support
4
+ classes inline with the tests instead of in separate files.
5
+
6
+ - Remove the async API.
7
+ The async API creates multiple threads that all call out to a method on a
8
+ single object. I don't think this is a good API because it forces its users
9
+ to deal with thread safety.
data/README.md CHANGED
@@ -12,57 +12,41 @@ __OVERVIEW__
12
12
  __DESCRIPTION__
13
13
 
14
14
  Provides a number of abstractions on top of spawning subprocesses and
15
- interprocess communication. The API is simple and supports both synchronous and
16
- asynchronous(non-blocking) types of programming. It also supports implicit
17
- interprocess communication that can be easily configured to use the serializer
18
- of your choice(default is the [Marshal](http://rdoc.info/stdlib/core/Marshal)
19
- module).
15
+ interprocess communication. The API is simple and can be easily used to
16
+ spawn multiple subprocesses that can return Ruby objects back to the parent
17
+ process. Ruby objects are serialized before being sent between processes, and
18
+ you have the option to choose what serializer to use.The default is the
19
+ [Marshal](http://rdoc.info/stdlib/core/Marshal) module.
20
20
 
21
21
  __EXAMPLES__
22
22
 
23
23
  __1.__
24
24
 
25
- A demo of how to spawn three subprocesses. Although the block is executed in a
26
- subprocess its return value is returned to the parent process.
25
+ A demo of how to spawn two subprocesses.
27
26
 
28
27
  ```ruby
29
- messages = IProcess.spawn(3) { {msg: "hello"} }
30
- p messages # => [{msg: "hello"}, {msg: "hello"}, {msg: "hello"}]
28
+ messages = IProcess.spawn(2) { {msg: "hello"} }
29
+ p messages # => [{msg: "hello"}, {msg: "hello"}]
31
30
  ```
32
-
33
31
  __2.__
34
32
 
35
33
  You can spawn a subprocess with a block or with any object that responds to
36
- `#call`. If you had a worker that was too complicated as a block you could
37
- try this:
34
+ `call`. If you had a block that had become too complicated you could try
35
+ refactoring it into a class:
38
36
 
39
37
  ```ruby
40
- class Worker
38
+ class Unit
41
39
  def initialize
42
40
  @num = 1
43
41
  end
44
42
 
45
43
  def call
46
- @num + 1
44
+ @num += 1
47
45
  end
48
46
  end
49
- IProcess.spawn 5, Worker.new # => [2, 2, 2, 2, 2]
47
+ IProcess.spawn 3, Unit.new # => [2,2,2]
50
48
  ```
51
- __3.__
52
-
53
- A demo of how to spawn two subprocesses asynchronously.
54
- The `Inbox#recv` method is a callback that XPool calls when a subprocess has
55
- finished executing. The example may not be the best, though:
56
49
 
57
- ```ruby
58
- class Inbox
59
- def recv(pid)
60
- puts "'#{pid}' has finished!"
61
- end
62
- end
63
- inbox = Inbox.new
64
- IProcess.spawn!(2, inbox) { Process.pid }
65
- ```
66
50
 
67
51
  __SERIALIZERS__
68
52
 
data/lib/iprocess.rb CHANGED
@@ -40,25 +40,6 @@ class IProcess
40
40
  fork(number_of, obj, &worker).map(&:result)
41
41
  end
42
42
 
43
- #
44
- # Spawn one or more subprocesse(s) asynchronously.
45
- #
46
- # @param [#recv] inbox
47
- # An object who can receive messages through the {#recv} method.
48
- #
49
- # @param
50
- # (see IProcess.spawn)
51
- #
52
- # @return [Array<IProcess>]
53
- #
54
- def self.spawn!(number_of, inbox, obj = nil, &worker)
55
- forks = fork number_of, obj, &worker
56
- forks.each do |subprocess|
57
- t = Thread.new { inbox.recv subprocess.result }
58
- at_exit { t.join }
59
- end
60
- end
61
-
62
43
  def self.fork(number_of = 1, obj = nil, &worker)
63
44
  worker = obj || worker
64
45
  Array.new(number_of) do
@@ -1,3 +1,3 @@
1
1
  class IProcess
2
- VERSION = '5.1.3'
2
+ VERSION = '6.0.0'
3
3
  end
@@ -1,31 +1,18 @@
1
1
  require_relative 'setup'
2
2
  class IProcessTest < Test::Unit::TestCase
3
- def test_spawn
4
- results = IProcess.spawn(2) { :ok }
5
- assert_equal [:ok, :ok], results
6
- end
7
-
8
- def test_spawn_with_non_proc_worker
9
- klass = Class.new do
10
- def call
11
- :ok
12
- end
3
+ class Unit
4
+ def call
5
+ 42
13
6
  end
14
- results = IProcess.spawn 2, klass.new
15
- assert_equal [:ok, :ok], results
16
7
  end
17
8
 
18
- def test_async_spawn!
19
- inbox = Inbox.new
20
- IProcess.spawn!(2, inbox) { {ok: true} }
21
- sleep 0.1
22
- assert_equal [{ok: true}, {ok: true}], inbox.messages
9
+ def test_spawn
10
+ results = IProcess.spawn(2) { 42 }
11
+ assert_equal [42, 42], results
23
12
  end
24
13
 
25
- def test_async_spawn_with_raise
26
- inbox = Inbox.new
27
- IProcess.spawn!(2, inbox) { raise RuntimeError, "", [] }
28
- sleep 0.1
29
- assert_equal [nil, nil] inbox.messages
14
+ def test_spawn_with_non_proc_worker
15
+ results = IProcess.spawn 2, Unit.new
16
+ assert_equal [42, 42], results
30
17
  end
31
18
  end
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: 5.1.3
4
+ version: 6.0.0
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: 2013-02-24 00:00:00.000000000 Z
12
+ date: 2013-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ichannel
@@ -39,6 +39,7 @@ files:
39
39
  - .pryrc
40
40
  - .travis.yml
41
41
  - .yardopts
42
+ - ChangeLog.txt
42
43
  - Gemfile
43
44
  - LICENSE.txt
44
45
  - README.md
@@ -47,7 +48,6 @@ files:
47
48
  - lib/iprocess.rb
48
49
  - lib/iprocess/version.rb
49
50
  - test/setup.rb
50
- - test/support/inbox.rb
51
51
  - test/test_IProcess_class.rb
52
52
  homepage: https://github.com/robgleeson/iprocess
53
53
  licenses: []
@@ -76,6 +76,5 @@ summary: A number of abstractions on top of spawning subprocesses and interproce
76
76
  communication.
77
77
  test_files:
78
78
  - test/setup.rb
79
- - test/support/inbox.rb
80
79
  - test/test_IProcess_class.rb
81
80
  has_rdoc:
@@ -1,13 +0,0 @@
1
- class Inbox
2
- def initialize
3
- @msgs = []
4
- end
5
-
6
- def messages
7
- @msgs
8
- end
9
-
10
- def recv(msg)
11
- @msgs << msg
12
- end
13
- end