step

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package step has the durable steps a flow function calls: Run, Sleep, SleepUntil, WaitForEvent, Invoke and Send.

How replay works: the engine calls the function from the top on every request, with the results of finished steps (the memo). A step that is in the memo returns its stored result at once. A step that is new is run (for Run) or reported to the engine (the others), and then the SDK stops the function with a special panic that client.Serve() recovers.

So do not swallow that panic. If you recover() around step calls, call Repanic first:

defer func() {
	if r := recover(); r != nil {
		step.Repanic(r) // lets the SDK stop the function
		// ... your own handling
	}
}()

Step IDs must be stable between calls. The same ID used again (in a loop) is fine: repeats get ":1", ":2", ... added before hashing. Inside group.Parallel, give each step its own ID.

Do not call steps from goroutines you start yourself; use group.Parallel.

Index

Constants

This section is empty.

Variables

View Source
var ErrEventNotReceived = errors.New("flow: event not received before the timeout")

ErrEventNotReceived is returned by WaitForEvent when the wait timed out.

View Source
var ErrNotInFunction = core.ErrNotInFunction

ErrNotInFunction is returned by step calls made outside a flow function or inside another step's callback.

Functions

func IdempotencyKey

func IdempotencyKey(ctx context.Context) string

IdempotencyKey returns "<runId>:<hashed step id>" inside a Run callback. It is the same on every attempt, so pass it to outside APIs that take one. It is empty outside a Run callback.

func Invoke

func Invoke[T any](ctx context.Context, id string, opts InvokeOpts) (T, error)

Invoke calls another flow function and returns its output. If the child fails, Invoke returns a *StepError.

func IsControlPanic

func IsControlPanic(r any) bool

IsControlPanic reports whether a recovered value is the SDK's control panic.

func Repanic

func Repanic(r any)

Repanic panics again with r if r is the SDK's control panic. Call it first in any recover() that can catch step calls.

func Run

func Run[T any](ctx context.Context, id string, fn func(ctx context.Context) (T, error)) (T, error)

Run runs fn once, keeps its result, and returns the kept result on replay. If fn returns an error, the step fails and the engine retries it (wrap the error with flow.NoRetryError or flow.RetryAtError to change that). When the step is out of retries, Run returns a *StepError.

func Send

func Send(ctx context.Context, id string, events ...core.Event) ([]string, error)

Send sends one or more events from the function, once (not again on replay). It returns the event IDs.

func Sleep

func Sleep(ctx context.Context, id string, d time.Duration) error

Sleep pauses the function for d.

func SleepUntil

func SleepUntil(ctx context.Context, id string, t time.Time) error

SleepUntil pauses the function until t.

func WaitForEvent

func WaitForEvent[T any](ctx context.Context, id string, opts WaitForEventOpts) (T, error)

WaitForEvent waits for an event and returns it. T is the event type, for example flow.GenericEvent[MyData]. On timeout it returns ErrEventNotReceived.

Types

type InvokeOpts

type InvokeOpts struct {
	// FunctionID is the full ID "<appId>-<functionId>". It can be in another
	// app, in any language.
	FunctionID string
	// Data becomes the child's event data.
	Data any
	// User becomes the child's event user field.
	User any
	// Timeout stops waiting after this long; the step then fails with
	// InvokeTimeout. Zero means no timeout.
	Timeout time.Duration
}

InvokeOpts says which function to call.

type StepError

type StepError = core.StepError

StepError is returned by a step whose stored result is an error: the step ran out of retries, or an invoked function failed. Check for it with errors.As to run compensation steps.

type WaitForEventOpts

type WaitForEventOpts struct {
	// Event is the name of the event to wait for.
	Event string
	// Timeout is how long to wait. Required.
	Timeout time.Duration
	// Match is a field path in both events, for example "data.userId".
	Match *string
	// If is an expression over event (the trigger) and async (the new event).
	If *string
}

WaitForEventOpts says which event to wait for.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL