Class: Smith::Tool::CallReservation
- Inherits:
-
Object
- Object
- Smith::Tool::CallReservation
- Extended by:
- Dry::Initializer
- Defined in:
- lib/smith/tool/call_reservation.rb
Instance Method Summary collapse
- #claim ⇒ Object
-
#initialize ⇒ CallReservation
constructor
A new instance of CallReservation.
- #settle! ⇒ Object
Constructor Details
#initialize ⇒ CallReservation
Returns a new instance of CallReservation.
14 15 16 17 18 19 |
# File 'lib/smith/tool/call_reservation.rb', line 14 def initialize(...) super @claimed = 0 @settled = false @mutex = Mutex.new end |
Instance Method Details
#claim ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/smith/tool/call_reservation.rb', line 21 def claim @mutex.synchronize do return false if @settled || @claimed >= limit @claimed += 1 true end end |
#settle! ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/smith/tool/call_reservation.rb', line 30 def settle! Thread.handle_interrupt(Exception => :never) do @mutex.synchronize do return if @settled ledger&.reconcile!(ledger_reservation, @claimed) @settled = true end end end |