worker

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package worker provides the goroutine-lifecycle boilerplate shared by every background process in the app (the orders outbox relay, the notifier consume loop). It is deliberately tiny: the value is having the error-prone concurrency plumbing — a single goroutine, context cancellation, WaitGroup join, idempotent stop — written and tested once.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Runner

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

Runner supervises one background goroutine. Embed it in a service and drive it with Start/Stop; the loop function receives a context that is cancelled when Stop is called, and Stop blocks until the goroutine has returned.

func (*Runner) Start

func (r *Runner) Start(loop func(context.Context))

Start launches loop in a new goroutine. loop must return when its context is cancelled (Stop cancels it). Call Start once.

func (*Runner) Stop

func (r *Runner) Stop()

Stop cancels the loop's context and waits for the goroutine to exit. It is idempotent and safe to call from multiple goroutines; calling it before Start (or twice) is a no-op that cannot panic.

Jump to

Keyboard shortcuts

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