taskevent

package
v0.58.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: AGPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package taskevent provides a decoupled, context-scoped event bus for task lifecycle progress. Producers (task implementations) emit events via Emit; consumers (e.g. the API progress store, the Telegram message editor) register as Sinks and are injected through context. This keeps the task layer free of any concrete progress-display dependency, so new task types gain progress reporting for free and new observers can be added without touching tasks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Emit

func Emit(ctx context.Context, e Event)

Emit broadcasts an event to all sinks carried by ctx. It is a no-op when no sink is attached, so producers can call it unconditionally.

func WithSink

func WithSink(ctx context.Context, sinks ...Sink) context.Context

WithSink returns a ctx carrying the given sinks. Multiple sinks can be passed and all will receive every emitted event. Sinks already present in ctx are preserved.

Types

type Event

type Event struct {
	TaskID          string
	Phase           Phase
	TotalBytes      int64
	DownloadedBytes int64
	TotalFiles      int
	DownloadedFiles int
	Err             error
}

Event describes a single progress observation for a task. Byte fields are populated by byte-stream tasks; file-count fields by count-based tasks. A task may fill whichever subset it has; observers ignore zero values.

type Phase

type Phase int

Phase marks a stage in a task's lifecycle.

const (
	PhaseStart Phase = iota
	PhaseProgress
	PhaseDone
)

func (Phase) String

func (p Phase) String() string

type Sink

type Sink interface {
	Emit(Event)
}

Sink receives task events. Implementations must be safe for concurrent use.

type SinkFunc

type SinkFunc func(Event)

SinkFunc is a function adapter for Sink.

func (SinkFunc) Emit

func (f SinkFunc) Emit(e Event)

Jump to

Keyboard shortcuts

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