forked from grosser/parallel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Parallel#find and Parallel#first_result grosser#273
In addtion to Parallel::Kill and Parallel::Break, a new Exception class named Parallel::Return allows raising an Exception which wraps a result value. That wrapped result will be unwrapped. When a method expects a single result, the option `:return_one` must be provided, because a given Enumeration might not contain a matching element or result.
- Loading branch information
Showing
6 changed files
with
122 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require './spec/cases/helper' | ||
STDOUT.sync = true # otherwise results can go weird... | ||
|
||
result = "" | ||
[{in_processes: 2}, {in_threads: 2}].each do |options| | ||
x = ["bob", "alice", "ellcs", "grosser"] | ||
result = Parallel.find(x, options) do |s| | ||
s.include?("ll") | ||
end | ||
end | ||
|
||
print result |
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,13 @@ | ||
require './spec/cases/helper' | ||
STDOUT.sync = true # otherwise results can go weird... | ||
|
||
result = "i should be nil" | ||
[{in_processes: 2}, {in_threads: 2}].each do |options| | ||
x = ["bob", "alice", "ellcs", "grosser"] | ||
result = Parallel.find(x, options) do |o| | ||
# nothing matches | ||
false | ||
end | ||
end | ||
|
||
print result.inspect |
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,12 @@ | ||
require './spec/cases/helper' | ||
STDOUT.sync = true # otherwise results can go weird... | ||
|
||
result = "" | ||
[{in_processes: 2}, {in_threads: 2}].each do |options| | ||
x = ["bob", "alice", "ellcs", "grosser"] | ||
result = Parallel.first_result(x, options) do |s| | ||
s.include?("ll") && s | ||
end | ||
end | ||
|
||
print result |
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,13 @@ | ||
require './spec/cases/helper' | ||
STDOUT.sync = true # otherwise results can go weird... | ||
|
||
result = "i should be nil" | ||
[{in_processes: 2}, {in_threads: 2}].each do |options| | ||
x = ["bob", "alice", "ellcs", "grosser"] | ||
result = Parallel.first_result(x, options) do |o| | ||
# nothing matches | ||
false | ||
end | ||
end | ||
|
||
print result.inspect |
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