worker

package
v0.2.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 2 Imported by: 0 modules, 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 worker runs blocking work off the loop goroutine: one goroutine at a time, in posting order, over a bounded queue. The goroutine lives only while work is queued, so an idle Queue costs nothing and a Stop leaves nothing behind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue runs posted functions in order. Create it with New.

func New

func New(capacity int) *Queue

New returns a queue holding at most capacity functions beyond the one running.

func (*Queue) Post

func (q *Queue) Post(fn func()) bool

Post queues fn without blocking and reports whether it was taken: a full or stopped queue refuses it.

func (*Queue) Settle

func (q *Queue) Settle(limit time.Duration) bool

Settle waits until everything posted so far ran, at most for limit, and reports whether it did.

func (*Queue) Stop

func (q *Queue) Stop(limit time.Duration) bool

Stop refuses later posts, lets queued work finish, and waits at most for limit, reporting whether the work ended. A function stuck past limit keeps its goroutine until it returns; the queue is dead either way. Safe to call twice.

Jump to

Keyboard shortcuts

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