Class: Restate::AttemptFinishedEvent
- Inherits:
-
Object
- Object
- Restate::AttemptFinishedEvent
- Defined in:
- lib/restate/context.rb
Overview
Signals when the current invocation attempt has finished — either the handler completed, the connection was lost, or a transient error occurred.
Use this to clean up attempt-scoped resources (open connections, temp files, etc.) that should not outlive the current attempt.
Available via ctx.request.attempt_finished_event.
Instance Method Summary collapse
-
#initialize ⇒ AttemptFinishedEvent
constructor
A new instance of AttemptFinishedEvent.
-
#set! ⇒ Object
Marks the event as set and wakes all waiters.
-
#set? ⇒ Boolean
Returns true if the attempt has finished.
-
#wait ⇒ Object
Blocks the current fiber/thread until the attempt finishes.
Constructor Details
#initialize ⇒ AttemptFinishedEvent
Returns a new instance of AttemptFinishedEvent.
20 21 22 23 24 |
# File 'lib/restate/context.rb', line 20 def initialize @mutex = Mutex.new @set = false @waiters = [] end |
Instance Method Details
#set! ⇒ Object
Marks the event as set and wakes all waiters. Called internally by the SDK when the attempt ends.
47 48 49 50 51 52 53 |
# File 'lib/restate/context.rb', line 47 def set! @mutex.synchronize do @set = true @waiters.each { |w| w.push(true) } @waiters.clear end end |
#set? ⇒ Boolean
Returns true if the attempt has finished.
27 28 29 |
# File 'lib/restate/context.rb', line 27 def set? @set end |
#wait ⇒ Object
Blocks the current fiber/thread until the attempt finishes.
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/restate/context.rb', line 32 def wait return if @set waiter = nil @mutex.synchronize do unless @set waiter = Thread::Queue.new @waiters << waiter end end waiter&.pop end |