queue

package
v1.15.13 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package queue implements an experimental background queue for cleanup jobs. Beware: It's likely broken. We can easily close a channel which might later be written to. The current locking is but a poor workaround. A better implementation would create a queue object in main, pass it through and wait for the channel to be empty before leaving main. Will do that later.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithQueue

func WithQueue(ctx context.Context, q *Queue) context.Context

WithQueue adds the given queue to the context. Add a nil queue to disable queuing in this context.

Types

type Queue

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

Queue is a serialized background processing unit.

func New

func New(ctx context.Context) *Queue

New creates a new queue.

func (*Queue) Add

func (q *Queue) Add(t Task) Task

Add enqueues a new task.

func (*Queue) Close added in v1.14.0

func (q *Queue) Close(ctx context.Context) error

Close waits for all tasks to be processed. Must only be called once on shutdown.

func (*Queue) Idle added in v1.12.8

func (q *Queue) Idle(maxWait time.Duration) error

Idle returns nil the next time the queue is empty.

type Queuer

type Queuer interface {
	Add(Task) Task
	Close(context.Context) error
	Idle(time.Duration) error
}

Queuer is a queue interface.

func GetQueue

func GetQueue(ctx context.Context) Queuer

GetQueue returns an existing queue from the context or returns a noop one.

type Task

type Task func(ctx context.Context) (context.Context, error)

Task is a background task.

Jump to

Keyboard shortcuts

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