parallel 1.23.0 → 1.24.0

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: 7b8bb887652e89a339de17f31e8482aec8664426b2b12eb11566779f53153a56
4
- data.tar.gz: e5fa1401f5748de7216a6d973d1ca1a2af514caeaec1dacafb153d2a5538334d
3
+ metadata.gz: f7b4a5662ef68724c75c2d655d9bd09ad109edc02d3199a0744093544608f74b
4
+ data.tar.gz: 247f7f3745c42cdafeb5d403fff250e99b99a56d4dc4948050dcf20ecb60d183
5
5
  SHA512:
6
- metadata.gz: 481a4b04da349a2eb88cdcab724dc3c47efe757dcb61889a3105d0097fb3255ff6283470f6c2bc636c1bd053e274516fddfa33f8d362e8208f6f57638864ca48
7
- data.tar.gz: 9093769c22e258cb921c1ab6ead1c7083fcc1d315b7bc268dff807c0fe1c4468b4316171e5f837283d7387ecdb01284f55763b60912c4bce7548aa9c869cc57b
6
+ metadata.gz: 18f62ea9fefb30bda9b89f0189074da99572c5c17fb93ba28e553b0eb9f6d7a61bd70ba423004b138b05c3c86f8e04fd32fce81da40a68c0bdca39e263b8b892
7
+ data.tar.gz: dca61c9e3cab22de0ad064c96c55afc88177214108d6bdbfb8e9a93343f23d6ee321c83aa6c4cfa9ee33da79d01802d7b952f3dd0360f9cca26e5da78a4117fa
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Parallel
3
- VERSION = Version = '1.23.0' # rubocop:disable Naming/ConstantName
3
+ VERSION = Version = '1.24.0' # rubocop:disable Naming/ConstantName
4
4
  end
data/lib/parallel.rb CHANGED
@@ -640,10 +640,34 @@ module Parallel
640
640
  end
641
641
 
642
642
  def instrument_finish(item, index, result, options)
643
- return unless on_finish = options[:finish]
643
+ return unless (on_finish = options[:finish])
644
+ return instrument_finish_in_order(item, index, result, options) if options[:finish_in_order]
644
645
  options[:mutex].synchronize { on_finish.call(item, index, result) }
645
646
  end
646
647
 
648
+ # yield results in the order of the input items
649
+ # needs to use `options` to store state between executions
650
+ # needs to use `done` index since a nil result would also be valid
651
+ def instrument_finish_in_order(item, index, result, options)
652
+ options[:mutex].synchronize do
653
+ # initialize our state
654
+ options[:finish_done] ||= []
655
+ options[:finish_expecting] ||= 0 # we wait for item at index 0
656
+
657
+ # store current result
658
+ options[:finish_done][index] = [item, result]
659
+
660
+ # yield all results that are now in order
661
+ break unless index == options[:finish_expecting]
662
+ index.upto(options[:finish_done].size).each do |i|
663
+ break unless (done = options[:finish_done][i])
664
+ options[:finish_done][i] = nil # allow GC to free this item and result
665
+ options[:finish].call(done[0], i, done[1])
666
+ options[:finish_expecting] += 1
667
+ end
668
+ end
669
+ end
670
+
647
671
  def instrument_start(item, index, options)
648
672
  return unless on_start = options[:start]
649
673
  options[:mutex].synchronize { on_start.call(item, index) }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parallel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.23.0
4
+ version: 1.24.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
11
+ date: 2023-12-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: michael@grosser.it
@@ -24,8 +24,8 @@ licenses:
24
24
  - MIT
25
25
  metadata:
26
26
  bug_tracker_uri: https://github.com/grosser/parallel/issues
27
- documentation_uri: https://github.com/grosser/parallel/blob/v1.23.0/Readme.md
28
- source_code_uri: https://github.com/grosser/parallel/tree/v1.23.0
27
+ documentation_uri: https://github.com/grosser/parallel/blob/v1.24.0/Readme.md
28
+ source_code_uri: https://github.com/grosser/parallel/tree/v1.24.0
29
29
  wiki_uri: https://github.com/grosser/parallel/wiki
30
30
  post_install_message:
31
31
  rdoc_options: []