forkner 1.1 → 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.
- checksums.yaml +4 -4
- data/README.md +54 -7
- data/lib/forkner.rb +2 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5cfc51f0c6ff1c5aad52b94e669c788d00ca61d268618229941e5f96e5f9e384
|
4
|
+
data.tar.gz: 90f35b9917c65ed2ca0884e66c73ce574c0365ea0d86a44a1a6221ed4870c4bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: afd4a6b35e80f47838694bd38a9d0b658e6631acd093826bd8401662a041cef22ec18bd2a46a3723d264b1a37fc35fdbe84ab5634115c03c96607cadabd09ea3
|
7
|
+
data.tar.gz: 21caed2b5a0a6ed84ef87e7bb6c060a04675f92984e8f8af592641971fed49df6e37f64a2a622e2cd57baceebfc7b5f777cabe4ab20881f0e0e88b69bf113af1
|
data/README.md
CHANGED
@@ -8,7 +8,19 @@ them when they finish.
|
|
8
8
|
Consider a situation in which you need to run a bunch of parallel processes, but
|
9
9
|
no more than five at a time. You might do that like this:
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
require 'forkner'
|
13
|
+
|
14
|
+
Forkner.container(5) do |forkner|
|
15
|
+
100.times do
|
16
|
+
forkner.child do
|
17
|
+
# do stuff in the child process
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# we won't get to this point until all child processes are done
|
23
|
+
```
|
12
24
|
|
13
25
|
First we load the `forkner` gem. Then we call Forkner's container `method`. All
|
14
26
|
child processes within `container` will completed before the method is done.
|
@@ -35,7 +47,23 @@ processes, finish the block with a value that can be stored as JSON.
|
|
35
47
|
|
36
48
|
Consider this example:
|
37
49
|
|
38
|
-
|
50
|
+
```ruby
|
51
|
+
Forkner.container(5) do |forkner|
|
52
|
+
forkner.reaper() do |rv|
|
53
|
+
puts '-----'
|
54
|
+
puts rv['myrand']
|
55
|
+
puts rv['timestamp']
|
56
|
+
end
|
57
|
+
|
58
|
+
10.times do
|
59
|
+
forkner.child do
|
60
|
+
myrand = rand()
|
61
|
+
timestamp = Time.now
|
62
|
+
{'myrand'=>myrand, 'timestamp'=>timestamp}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
39
67
|
|
40
68
|
In this example, inside the `container` block we call the Forkner object's
|
41
69
|
`reaper` method with a block. In that block we get a single parameter which
|
@@ -57,7 +85,25 @@ Forkner object and call its `child` method. Just be sure to call the `wait_all`
|
|
57
85
|
method after all the child processes have been called. The following code does
|
58
86
|
exactly the same thing as the previous example.
|
59
87
|
|
60
|
-
|
88
|
+
```ruby
|
89
|
+
forkner = Forkner.new(5)
|
90
|
+
|
91
|
+
forkner.reaper() do |rv|
|
92
|
+
puts '-----'
|
93
|
+
puts rv['myrand']
|
94
|
+
puts rv['timestamp']
|
95
|
+
end
|
96
|
+
|
97
|
+
10.times do
|
98
|
+
forkner.child do
|
99
|
+
myrand = rand()
|
100
|
+
timestamp = Time.now
|
101
|
+
{'myrand'=>myrand, 'timestamp'=>timestamp}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
forkner.wait_all
|
106
|
+
```
|
61
107
|
|
62
108
|
## Install
|
63
109
|
|
@@ -72,7 +118,8 @@ mike@idocs.com
|
|
72
118
|
|
73
119
|
## History
|
74
120
|
|
75
|
-
| version | date
|
76
|
-
|
77
|
-
| 1.0 | Jan 7, 2020
|
78
|
-
| 1.1 | Jan 7, 2020
|
121
|
+
| version | date | notes |
|
122
|
+
|---------|--------------|------------------------------------------------------------------|
|
123
|
+
| 1.0 | Jan 7, 2020 | Initial upload. |
|
124
|
+
| 1.1 | Jan 7, 2020 | Fixed some typos. No changes to functionality. |
|
125
|
+
| 1.2 | Jan 19, 2020 | Fixed other documentation problems. No changes to functionality. |
|
data/lib/forkner.rb
CHANGED