Class: Restate::DurableFuture

Inherits:
Object
  • Object
show all
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

DurableCallFuture

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#handleObject (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

#awaitObject

Block until the result is available and return it. Caches across calls.

Returns:

  • (Object)

    the deserialized result



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).

Returns:

  • (Boolean)


33
34
35
# File 'lib/restate/durable_future.rb', line 33

def completed?
  @resolved || @ctx.completed?(@handle)
end