queue

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2021 License: MIT Imports: 4 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

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) Idle added in v1.12.8

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

Idle returns nil the next time the queue is empty

func (*Queue) Wait

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

Wait waits for all tasks to be processed. Must only be called once on shutdown. TODO: This should be called Close

type Queuer

type Queuer interface {
	Add(Task) Task
	Wait(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) error

Task is a background task

Jump to

Keyboard shortcuts

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