Class: Restate::DurableFuture
- Inherits:
-
Object
- Object
- Restate::DurableFuture
- Defined in:
- lib/restate/durable_future.rb
Overview
A durable future wrapping a VM handle. Lazily resolves on first await and caches the result. Returned by ctx.run and ctx.sleep.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
Instance Method Summary collapse
-
#await ⇒ Object
Block until the result is available and return it.
-
#completed? ⇒ Boolean
Check whether the future has completed (non-blocking).
-
#initialize(ctx, handle, serde: nil) ⇒ DurableFuture
constructor
A new instance of DurableFuture.
Constructor Details
#initialize(ctx, handle, serde: nil) ⇒ DurableFuture
Returns a new instance of DurableFuture.
10 11 12 13 14 15 16 |
# File 'lib/restate/durable_future.rb', line 10 def initialize(ctx, handle, serde: nil) @ctx = ctx @handle = handle @serde = serde @resolved = false @value = nil end |
Instance Attribute Details
#handle ⇒ Object (readonly)
Returns the value of attribute handle.
8 9 10 |
# File 'lib/restate/durable_future.rb', line 8 def handle @handle end |
Instance Method Details
#await ⇒ Object
Block until the result is available and return it. Caches across calls.
21 22 23 24 25 26 27 28 |
# File 'lib/restate/durable_future.rb', line 21 def await unless @resolved raw = @ctx.resolve_handle(@handle) @value = @serde ? @serde.deserialize(raw) : raw @resolved = true end @value end |
#completed? ⇒ Boolean
Check whether the future has completed (non-blocking).
33 34 35 |
# File 'lib/restate/durable_future.rb', line 33 def completed? @resolved || @ctx.completed?(@handle) end |