Skip to content

Instantly share code, notes, and snippets.

@keshihoriuchi
Created November 2, 2015 22:35
Show Gist options
  • Save keshihoriuchi/01b7bc38654d1e30639e to your computer and use it in GitHub Desktop.
Save keshihoriuchi/01b7bc38654d1e30639e to your computer and use it in GitHub Desktop.
Thread.abort_on_exceptionを書き換えるコードを安全に並列実行する
require 'parallel'
require 'retryable'
res = Parallel.map((1..10).to_a, in_threads: 10) do |a|
Retryable.retryable(tries: 50) do
Parallel.map([a], in_processes: 1) do |b|
Thread.current.abort_on_exception = true
exit if [1, 2].sample == 1
b + 1
end[0]
end
end
p res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment