Created
September 18, 2014 07:32
-
-
Save yuroyoro/c9d65806030f845d96e3 to your computer and use it in GitHub Desktop.
Fiber使って、ActiveRecord::Base.transactionのblcok内でyieldして、beginとcommit/rollbackを別々の場所で実行するヤツ
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
fiber = Fiber.new {|commit| | |
puts "fiber start" | |
ActiveRecord::Base.transaction { | |
puts "begin" | |
Fiber.yield | |
raise ActiveRecord::Rollback unless commit | |
puts "commit" | |
} | |
puts "fiber end" | |
} | |
fiber.resume | |
puts "in tx" | |
dosomething_in_transaction() | |
fiber.resume(false) # rollback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment