Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept a block passed to pessimistic lock! #4503

Closed

Conversation

exviva
Copy link
Contributor

@exviva exviva commented Jan 17, 2012

This allows to shorten a typical idiom of calling the lock!
method as first within a transaction:

class Order < ActiveRecord::Base
  def cancel!
    transaction do
      lock!
      # ... cancelling logic
    end
  end
end

# becomes:

class Order < ActiveRecord::Base
  def cancel!
    lock! do
      # ... cancelling logic
    end
  end
end

@tenderlove this is the port of #4479 you asked for. Please backport to 3-2-stable as well.

This allows to shorten a typical idiom of calling the `lock!`
method as first within a transaction:

    class Order < ActiveRecord::Base
      def cancel!
        transaction do
          lock!
          # ... cancelling logic
        end
      end
    end

    # becomes:

    class Order < ActiveRecord::Base
      def cancel!
        lock! do
          # ... cancelling logic
        end
      end
    end
@dasch
Copy link
Contributor

dasch commented Jan 18, 2012

I don't feel that lock! is a very descriptive name here, as it doesn't imply that you're entering a transaction. How about locked_transaction or transaction_with_lock?

@exviva
Copy link
Contributor Author

exviva commented Jan 18, 2012

I was thinking of with_lock or with_pessimistic_lock. What do you think?

@dasch
Copy link
Contributor

dasch commented Jan 18, 2012

Yeah, those sound good.

@tenderlove
Copy link
Member

@exviva either of those sounds fine. Please update and I'll merge. :-)

@exviva
Copy link
Contributor Author

exviva commented Jan 18, 2012

Re-opened as #4531

@exviva exviva deleted the accept_a_block_in_pessimistic_lock_master branch March 10, 2016 20:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants