-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #339 from shaicoleman/finish-in-order
Add :finish_in_order option
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require './spec/cases/helper' | ||
|
||
class Callback | ||
def self.call(_item) | ||
sleep rand * 0.01 | ||
end | ||
end | ||
|
||
method = ENV.fetch('METHOD') | ||
in_worker_type = "in_#{ENV.fetch('WORKER_TYPE')}".to_sym | ||
$stdout.sync = true | ||
|
||
items = 1..9 | ||
finish = ->(item, _index, _result) { puts "finish #{item}" } | ||
options = { in_worker_type => 4, finish: finish, finish_in_order: true } | ||
if in_worker_type == :in_ractors | ||
Parallel.public_send(method, items, options.merge(ractor: [Callback, :call])) | ||
else | ||
Parallel.public_send(method, items, options) { |item| Callback.call(item) } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters