nodes_dispatch

package
v0.20.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package nodes_dispatch provides the `dispatch.run` action, which tries explicitly listed actions in order and returns the first successful result.

Typical use:

dispatch.run @{ members: [runtime.fail, runtime.const], payload: { value: "x" } }

Index

Constants

View Source
const ID = "nodes_dispatch"

Variables

View Source
var Dispatch = action.New("dispatch.run", func(ctx context.Context, req DispatchReq) (any, error) {
	resolver := contracts.ActionResolverFromContext(ctx)
	if resolver == nil {
		return nil, xerr.Internal("dispatch: no action resolver in context")
	}

	var lastErr error
	for _, name := range req.Members {
		target, ok := resolver.Action(name)
		if !ok {
			lastErr = xerr.NotFound("dispatch: member not registered: " + name)
			continue
		}
		output, err := action.InvokeAny(ctx, target, req.Payload)
		if err == nil {
			return output, nil
		}
		lastErr = err
	}
	if lastErr == nil {
		lastErr = xerr.NotFound("dispatch: no member succeeded")
	}
	return nil, lastErr
}).Description("Tries each explicitly listed action in order until one succeeds").
	Tag("dispatch", "routing").
	Build()

Functions

func Bundle

func Bundle(_ map[string]string) core.Bundle

Types

type DispatchReq

type DispatchReq struct {
	Members []string `json:"members"`
	Payload any      `json:"payload"`
}

Jump to

Keyboard shortcuts

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