Class: Restate::DurableCallFuture

Inherits:
DurableFuture show all
Defined in:
lib/restate/durable_future.rb

Overview

A durable future for service/object/workflow calls. Adds invocation_id and cancel on top of DurableFuture. Returned by ctx.service_call, ctx.object_call, ctx.workflow_call.

Instance Attribute Summary

Attributes inherited from DurableFuture

#handle

Instance Method Summary collapse

Methods inherited from DurableFuture

#completed?

Constructor Details

#initialize(ctx, result_handle, invocation_id_handle, output_serde:) ⇒ DurableCallFuture

Returns a new instance of DurableCallFuture.



42
43
44
45
46
47
48
# File 'lib/restate/durable_future.rb', line 42

def initialize(ctx, result_handle, invocation_id_handle, output_serde:)
  super(ctx, result_handle)
  @invocation_id_handle = invocation_id_handle
  @output_serde = output_serde
  @invocation_id_resolved = false
  @invocation_id_value = nil
end

Instance Method Details

#awaitObject

Block until the result is available and return it. Deserializes via output_serde.



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/restate/durable_future.rb', line 51

def await
  unless @resolved
    raw = @ctx.resolve_handle(@handle)
    @value = if raw.nil? || @output_serde.nil?
               raw
             else
               @output_serde.deserialize(raw)
             end
    @resolved = true
  end
  @value
end

#cancelObject

Cancel the remote invocation.



76
77
78
# File 'lib/restate/durable_future.rb', line 76

def cancel
  @ctx.cancel_invocation(invocation_id)
end

#invocation_idString

Returns the invocation ID of the remote call. Lazily resolved.

Returns:

  • (String)

    the invocation ID



67
68
69
70
71
72
73
# File 'lib/restate/durable_future.rb', line 67

def invocation_id
  unless @invocation_id_resolved
    @invocation_id_value = @ctx.resolve_handle(@invocation_id_handle)
    @invocation_id_resolved = true
  end
  @invocation_id_value
end