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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 98545dd0b66a7ddefe057d382bea0880e6cae593f991492da264c09858ea051c
4
- data.tar.gz: ab41c7149d2c3cb9a8b8447deb75fb323c93b936f4dd59a0317f29a38e1477f1
3
+ metadata.gz: abb842c2b20ba5419535f1e0fa9cca60d8cb20070c311efe0fe6eda9d603f50d
4
+ data.tar.gz: 908cc20a1a04a2fdbe68f2afc80d0152fbaf6a77dd1f7092db6183687b6b8edb
5
5
  SHA512:
6
- metadata.gz: 33612ab356fcdc4f7e3af9d794e78bab489a516b950a0181c304a2dd7f40dabd6733c20ad5230be0ce2c5cb26c95a566b51b2993a78885b0b7d8807c8f0e0f4a
7
- data.tar.gz: 03a9baf31d37506a1c6a4d3e9c68fb268d40b5d6bbbe840f183d712d89007c79bef61b506c9085ebcb0add9e8c0a4e64cbc0f60ca470e0852d17f63db239ffb5
6
+ metadata.gz: d9c65d2ccebfbba7815f86bd118114c68b4382b59904bbf51457d036ff5c840c083c25b2f39bd82d0d606d1d18ea8da1aa3e7889bb1ae2aa8bcbf57d7434e982
7
+ data.tar.gz: 12c2c372b9261532404126a6a72359dd3037ca0afa21c9b357f754ecfe3c89474660259fbe3fa8a195f7832cf50930acf7d69c567a76f8391caeebb38d64b505
@@ -1,3 +1,11 @@
1
+ # 1.0.3
2
+
3
+ * Fix `Puli#map` executing tasks twice
4
+
5
+ # 1.0.2
6
+
7
+ * Make sure `Puli#map` returns results in the same order as the payloads for the tasks.
8
+
1
9
  # 1.0.1
2
10
 
3
11
  * Remove Jeweler and simplify gem building
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.
@@ -1,7 +1,7 @@
1
1
  require 'thread'
2
2
 
3
3
  class Puli
4
- VERSION = '1.0.2'
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
- result = yield(*payload)
27
- mux.synchronize { in_execution_order << Task.new(yield(*payload), index) }
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
@@ -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.2
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: 2019-09-22 00:00:00.000000000 Z
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.6
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