puli 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +26 -1
- data/lib/puli.rb +3 -3
- data/spec/puli_spec.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abb842c2b20ba5419535f1e0fa9cca60d8cb20070c311efe0fe6eda9d603f50d
|
4
|
+
data.tar.gz: 908cc20a1a04a2fdbe68f2afc80d0152fbaf6a77dd1f7092db6183687b6b8edb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9c65d2ccebfbba7815f86bd118114c68b4382b59904bbf51457d036ff5c840c083c25b2f39bd82d0d606d1d18ea8da1aa3e7889bb1ae2aa8bcbf57d7434e982
|
7
|
+
data.tar.gz: 12c2c372b9261532404126a6a72359dd3037ca0afa21c9b357f754ecfe3c89474660259fbe3fa8a195f7832cf50930acf7d69c567a76f8391caeebb38d64b505
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -35,7 +35,32 @@ end
|
|
35
35
|
# and will also raise TimeoutError up into the caller, regardless of whether
|
36
36
|
# Thread.abort_on_exception is set to true.
|
37
37
|
```
|
38
|
-
|
38
|
+
|
39
|
+
# Execution order (`map` vs. `each`)
|
40
|
+
|
41
|
+
Since `Puli#each` is presumed to generate side effects and should not slow down execution it yields immediately, so
|
42
|
+
the order of execution is undefined:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
puli = Puli.new(num_threads: 4, tasks: 1..10.to_a)
|
46
|
+
puli.each do |item| # Will yield numbers from 1 to 10 but in arbitrary order
|
47
|
+
fetch_item(item)
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
However `Puli#map` can "hold" its return value until the ordering can be re-established, and will always return
|
52
|
+
the tasks in order they were submitted or in the order the tasks were given in the `tasks:` keyword argument:
|
53
|
+
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
puli = Puli.new(num_threads: 4, tasks: 1..10.to_a)
|
57
|
+
fetched_items = puli.map do |i|
|
58
|
+
# Will run the block in arbitrary order among tasks, due to out-of-order execution
|
59
|
+
fetch_item(i)
|
60
|
+
end
|
61
|
+
fetched_items #=> [<Item 1>, <Item 2>, ...]_
|
62
|
+
```
|
63
|
+
|
39
64
|
## Contributing to puli
|
40
65
|
|
41
66
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/lib/puli.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'thread'
|
2
2
|
|
3
3
|
class Puli
|
4
|
-
VERSION = '1.0.
|
4
|
+
VERSION = '1.0.3'
|
5
5
|
|
6
6
|
Task = Struct.new(:payload, :index)
|
7
7
|
|
@@ -23,8 +23,8 @@ class Puli
|
|
23
23
|
in_execution_order = []
|
24
24
|
mux = Mutex.new
|
25
25
|
each do |*payload, index:|
|
26
|
-
|
27
|
-
mux.synchronize { in_execution_order << Task.new(
|
26
|
+
task_result = yield(*payload)
|
27
|
+
mux.synchronize { in_execution_order << Task.new(task_result, index) }
|
28
28
|
end
|
29
29
|
in_execution_order.sort_by(&:index).map(&:payload)
|
30
30
|
end
|
data/spec/puli_spec.rb
CHANGED
@@ -52,6 +52,18 @@ describe 'Puli' do
|
|
52
52
|
expect(order_of_execution).to eq(order_as_submitted)
|
53
53
|
end
|
54
54
|
|
55
|
+
it 'when mapping, only executes the workload once per task' do
|
56
|
+
order_as_submitted = (1..64).to_a
|
57
|
+
mux = Mutex.new
|
58
|
+
p = Puli.new(num_threads: 4, tasks: order_as_submitted)
|
59
|
+
execution_counter = 0
|
60
|
+
order_of_execution = p.map do |number|
|
61
|
+
sleep(rand / 14)
|
62
|
+
mux.synchronize { execution_counter += 1 }
|
63
|
+
end
|
64
|
+
expect(execution_counter).to eq(order_as_submitted.length)
|
65
|
+
end
|
66
|
+
|
55
67
|
it 'allows mapping over the result' do
|
56
68
|
p = Puli.new(num_threads: 4)
|
57
69
|
20.times {|i| p << i }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julik Tarkhanov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
111
|
-
rubygems_version: 3.0.
|
111
|
+
rubygems_version: 3.0.3
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: A corded thread pool for bursty threaded workloads
|