client

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package client is the producer side: Enqueue tasks and await responses.

Index

Constants

This section is empty.

Variables

View Source
var ErrClientClosed = errors.New("ebind: client closed")

ErrClientClosed is returned when a future is waited on after the client closes.

Functions

func Await

func Await[T any](ctx context.Context, f *Future) (T, error)

Await is a generic helper that wraps Future.Get with a typed return.

func EnqueueAsync

func EnqueueAsync(c *Client, fn any, args ...any) (string, error)

EnqueueAsync is fire-and-forget. Returns the task ID.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, nc *nats.Conn, opts Options) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) ID

func (c *Client) ID() string

type EnqueueOptions

type EnqueueOptions struct {
	Deadline    time.Time // absolute deadline for handler execution
	TraceCtx    map[string]string
	RetryPolicy *task.RetryPolicy // per-task override; worker falls back to its Options defaults when nil
	DAGID       string            // workflow-level: identifies the parent DAG
	StepID      string            // workflow-level: identifies this step within the DAG
	Target      string            // logical or concrete placement claim for targeted execution
	// SkipResponse: don't register a waiter, return nil Future (fire-and-forget).
	SkipResponse bool
}

type Future

type Future struct {
	// contains filtered or unexported fields
}

func Enqueue

func Enqueue(c *Client, fn any, args ...any) (*Future, error)

Enqueue publishes a task. fn is a function reference used as type witness and name source. args must match fn's signature (ctx is supplied automatically on the worker side).

func EnqueueOpts

func EnqueueOpts(c *Client, fn any, opts EnqueueOptions, args ...any) (*Future, error)

func (*Future) Get

func (f *Future) Get(ctx context.Context, out any) error

Get blocks until the task response arrives or ctx is canceled. Unmarshals the result into out. Pass nil for out if the handler returns only error.

func (*Future) GetRaw

func (f *Future) GetRaw(ctx context.Context) (json.RawMessage, error)

GetRaw returns the raw JSON-encoded result (or nil for error-only handlers).

func (*Future) ID

func (f *Future) ID() string

type Options

type Options struct {
	// ClientID scopes response subjects to this client. Defaults to a random uuid.
	ClientID string
	// DefaultTimeout is the context timeout used if Enqueue is called with context.Background.
	DefaultTimeout time.Duration
}

Jump to

Keyboard shortcuts

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