Help us shape the future of Go! Take the 2026 Go Developer Survey

nodes_dispatch

package
v0.61.1 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 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")
	}
	if len(req.Members) == 0 {
		return nil, xerr.NotFound("dispatch: no member succeeded")
	}

	var lastErr error
	candidates := make([]action.AnyAction, 0, len(req.Members))
	for _, name := range req.Members {
		member := name
		candidates = append(candidates, action.New("dispatch.member", func(_ context.Context, payload any) (any, error) {

			target, ok := resolver.Action(member)
			if !ok {
				lastErr = xerr.NotFound("dispatch: member not registered: " + member)
				return nil, lastErr
			}

			output, err := action.InvokeAny(ctx, target, payload)
			if err != nil {
				lastErr = err
			}
			return output, err
		}).Build())
	}

	firstSuccess := action.FirstSuccessAny("dispatch.run", candidates...).Build()

	output, err := action.InvokeAny(context.WithoutCancel(ctx), firstSuccess, req.Payload)
	if err != nil {
		if lastErr != nil {
			return nil, lastErr
		}
		return nil, err
	}
	return output, nil
}).Description("Tries each explicitly listed action in order until one succeeds").
	Tag("dispatch", "routing").
	Build()

Functions

func Bundle

func Bundle(_ map[string]string) compiler.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