Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions await-signals/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
* The sample demonstrates how to deal with multiple signals that can come out of order and require actions
* if a certain signal not received in a specified time interval.

This specific sample receives three signals: Signal1, Signal2, Signal3. They have to be processed in the
This specific sample receives three signals: Signal1, Signal2, Signal3. They have to be processed in
sequential order, but they can be received out of order.
There are two timeouts to enforce.
The first one is the maximum time between signals.
The second limits the total time since the first signal received.

A naive implementation of such use case would use a single loop that contains a Selector to listen on three
signals and a timer. Something like:
A naive implementation would use a single loop that contains a Selector to listen on three signals and a timer.
Something like:

for {
selector := workflow.NewSelector(ctx)
Expand Down
40 changes: 23 additions & 17 deletions nexus/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,30 @@ import (
"github.com/temporalio/samples-go/nexus/service"
)

// NewSyncOperation is a meant for exposing simple RPC handlers.
var EchoOperation = temporalnexus.NewSyncOperation(service.EchoOperationName, func(ctx context.Context, c client.Client, input service.EchoInput, options nexus.StartOperationOptions) (service.EchoOutput, error) {
// The method is provided with an SDK client that can be used for arbitrary calls such as signaling, querying,
// and listing workflows but implementations are free to make arbitrary calls to other services or databases, or
// perform simple computations such as this one.
return service.EchoOutput(input), nil
})
// NewSyncOperation is meant for exposing simple RPC handlers.
var EchoOperation = temporalnexus.NewSyncOperation(
service.EchoOperationName,
func(ctx context.Context, c client.Client, input service.EchoInput, options nexus.StartOperationOptions) (service.EchoOutput, error) {
// The method is provided with an SDK client that can be used for arbitrary calls such as signaling, querying,
// and listing workflows but implementations are free to make arbitrary calls to other services or databases, or
// perform simple computations such as this one.
return service.EchoOutput(input), nil
})

// Use the NewWorkflowRunOperation constructor, which is the easiest way to expose a workflow as an operation.
// See alternatives at https://pkg.go.dev/go.temporal.io/sdk/temporalnexus.
var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, HelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) {
return client.StartWorkflowOptions{
// Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts.
// For this example, we're using the request ID allocated by Temporal when the caller workflow schedules
// the operation, this ID is guaranteed to be stable across retries of this operation.
ID: options.RequestID,
// Task queue defaults to the task queue this operation is handled on.
}, nil
})
var HelloOperation = temporalnexus.NewWorkflowRunOperation(
service.HelloOperationName,
HelloHandlerWorkflow,
func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) {
return client.StartWorkflowOptions{
// Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts.
// For this example, we're using the request ID allocated by Temporal when the caller workflow schedules
// the operation, this ID is guaranteed to be stable across retries of this operation.
ID: options.RequestID,
// Task queue defaults to the task queue this operation is handled on.
}, nil
})

func HelloHandlerWorkflow(_ workflow.Context, input service.HelloInput) (service.HelloOutput, error) {
switch input.Language {
Expand All @@ -49,4 +54,5 @@ func HelloHandlerWorkflow(_ workflow.Context, input service.HelloInput) (service
}
return service.HelloOutput{}, fmt.Errorf("unsupported language %q", input.Language)
}
// @@@SNIPEND

// @@@SNIPEND
Loading