nodes_dispatch

package
v0.98.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 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 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: [fail, noop], 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