iprocess 3.1.0 → 3.1.1

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 CHANGED
@@ -24,7 +24,7 @@ __1.__
24
24
 
25
25
  Three subprocesses are spawned. The return value of the block, even though executed
26
26
  in a subprocess, is returned to the parent process as long as it may be serialized
27
- by Marshal:
27
+ by Marshal(or the serializer of your choice, this is configurable):
28
28
 
29
29
  messages = IProcess.spawn(3) { {msg: "hello"} }
30
30
  p messages # => [{msg: "hello"}, {msg: "hello"}, {msg: "hello"}]
@@ -71,6 +71,23 @@ the `IProcess.serializer=` method:
71
71
 
72
72
  IProcess.serializer = JSON
73
73
 
74
+ I know JSON & Marshal(the default) are supported out of
75
+ the box because they implement both of those methods.
76
+ MessagePack does not however but you could easily write
77
+ a wrapper:
78
+
79
+ require 'msgpack'
80
+ obj = Class.new do
81
+ def self.dump(obj)
82
+ MessagePack.pack(obj)
83
+ end
84
+
85
+ def self.load(obj)
86
+ MessagePack.unpack(obj)
87
+ end
88
+ end
89
+ IProcess.serializer = obj
90
+
74
91
  __PLATFORM SUPPORT__
75
92
 
76
93
  _supported_
@@ -1,3 +1,3 @@
1
1
  class IProcess
2
- VERSION = '3.1.0'
2
+ VERSION = '3.1.1'
3
3
  end
data/lib/iprocess.rb CHANGED
@@ -23,7 +23,7 @@ class IProcess
23
23
  #
24
24
  # @overload spawn(number_of = 1, worker)
25
25
  #
26
- # Spawn one or more unit(s) of work.
26
+ # Spawn one or more subprocesses.
27
27
  #
28
28
  # @param [Integer] number_of
29
29
  # The number of subprocesses to spawn.
@@ -32,8 +32,8 @@ class IProcess
32
32
  # The unit of work to execute in a subprocess.
33
33
  #
34
34
  # @return [Array<Object>]
35
- # The return value of the unit if worker.
36
- #
35
+ # The return value(s) of the unit(s) of work.
36
+ #
37
37
  def spawn(*args, &worker)
38
38
  fork(*args, &worker).map(&:result)
39
39
  end
@@ -41,13 +41,13 @@ class IProcess
41
41
  #
42
42
  # @overload
43
43
  #
44
- # Spawn one or more unit(s) of work asynchronously.
44
+ # Spawn one or more subprocesses asynchronously.
45
45
  #
46
46
  # @param
47
47
  # (see IProcess.spawn)
48
48
  #
49
49
  # @return [Array<IProcess>]
50
- # An array of IProcess objects. See {#defer}.
50
+ # An array of IProcess objects. See {#report_to}.
51
51
  #
52
52
  def spawn!(*args, &worker)
53
53
  fork *args, &worker
@@ -64,7 +64,7 @@ class IProcess
64
64
 
65
65
  #
66
66
  # @param [#call] worker
67
- # A block or any object that responds to #call.
67
+ # A block or any object that implements #call.
68
68
  #
69
69
  # @raise [ArgumentError]
70
70
  # If 'worker' does not respond to #call.
@@ -89,14 +89,20 @@ class IProcess
89
89
  # @return [void]
90
90
  #
91
91
  def report_to(obj)
92
- Thread.new do
92
+ thr = Thread.new do
93
93
  Process.wait @pid
94
94
  obj.recv @channel.recv
95
95
  end
96
+ pid = Process.pid
97
+ at_exit do
98
+ if pid == Process.pid && thr.alive?
99
+ thr.join
100
+ end
101
+ end
96
102
  end
97
103
 
98
104
  #
99
- # Executes a unit of work in a subprocess.
105
+ # Executes a subprocess.
100
106
  #
101
107
  # @return [Fixnum]
102
108
  # The process ID of the spawned subprocess.
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.1.0
4
+ version: 3.1.1
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-10-27 00:00:00.000000000 Z
12
+ date: 2012-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yard