Futureパターン2

concurrent-rubyをつかうとfutureパターンが、かなりきれいに書ける。

github.com

require 'concurrent-edge'

Concurrent.future {
  raise "exception" if [true, false].sample
  true
}.then {|m|
  puts "succeed #{m}"  # 成功した時の処理、viewになげたり
}.rescue{|m|
  puts "failed #{m}" # 失敗した時の処理
}.then{|m|
  puts "finished" # finalize 
}

sleep 0.1