Created
April 3, 2012 15:04
-
-
Save zflat/2292754 to your computer and use it in GitHub Desktop.
rails with_lock
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
see http://guides.rubyonrails.org/3_2_release_notes.html | |
This makes it possible to write the following: | |
class Order < ActiveRecord::Base | |
def cancel! | |
transaction do | |
lock! | |
# ... cancelling logic | |
end | |
end | |
end | |
as: | |
class Order < ActiveRecord::Base | |
def cancel! | |
with_lock do | |
# ... cancelling logic | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment