queue

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 7 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 queue holds the work queues: one file per session and one for the inbox, a line per item. Its functions return typed errors, so the command line and the dashboard can say the same thing in their own way.

Index

Constants

View Source
const MaxFileBytes = 4 << 20

MaxFileBytes is how large a queue file may grow by adding: the reader keeps 8 MiB, and a file past that would lose its end the next time it is rewritten.

View Source
const MaxItem = 200

MaxItem is the longest item, in characters.

Variables

View Source
var ErrBlank = errors.New("nothing to queue")

ErrBlank says the text to queue holds nothing.

View Source
var ErrEmpty = errors.New("queue empty")

ErrEmpty says the queue has no items.

View Source
var ErrFull = errors.New("queue full: remove some items first")

ErrFull says a queue file has reached MaxFileBytes.

View Source
var ErrNoSession = errors.New("no such session")

ErrNoSession says a bulk change was asked for a session that has no folder here. Merge and Replace never make one: a session exists because a hook saw it, and a restore must not invent one.

Functions

func Fits added in v1.0.7

func Fits(items []textsafe.Text) int

Fits is how many of the items Replace would write. A plan that says how many items a queue will hold uses the same count.

func Label

func Label(id state.ID) string

Label is the short name of a queue: "inbox", or the first four characters of a session id.

func LabelFor added in v0.6.0

func LabelFor(st state.Store, id state.ID) string

LabelFor is the name a person is shown for a queue: the session's alias when it has one, and Label otherwise.

func Missing added in v1.0.7

func Missing(have []string, items []textsafe.Text) (add []textsafe.Text, skipped int)

Missing says which of items a queue that holds have lacks, in the order given, and how many were there already. Items are compared by text with the rule of the JSON (trailing spaces do not count), and by number: when have holds "x" once and items holds it twice, one is missing. Blank items are in neither count. Merge adds exactly these, and a plan that shows what a merge would add uses the same function.

func MissingAt added in v1.0.7

func MissingAt(have []string, items []textsafe.Text) (idx []int, skipped int)

MissingAt is Missing, giving the positions in items of the ones that are missing, for a caller that knows where each came from.

Types

type ChangedError

type ChangedError struct{ ID state.ID }

ChangedError says the queue is no longer what the caller saw.

func (*ChangedError) Error

func (e *ChangedError) Error() string

type MergeResult added in v1.0.7

type MergeResult struct {
	Added    int // appended to the queue
	Skipped  int // already in the queue, by text and by number
	NotAdded int // left out because the queue file reached MaxFileBytes
}

MergeResult says what a merge did. Items that were blank are in none of the counts.

type NoItemError

type NoItemError struct {
	ID state.ID
	N  int
}

NoItemError says there is no item at that position.

func (*NoItemError) Error

func (e *NoItemError) Error() string

type Queue

type Queue struct {
	Store state.Store
	Log   histlog.Log
}

Queue is the set of queues in a state folder. Log records each change once it has succeeded; the zero Log is off.

func (Queue) Add

func (q Queue) Add(id state.ID, text textsafe.Text) (int, error)

Add appends an item and returns how many items the queue now holds.

func (Queue) Count

func (q Queue) Count(id state.ID) int

Count is the number of non-empty lines.

func (Queue) Edit added in v0.6.0

func (q Queue) Edit(id state.ID, n int, text textsafe.Text, guard *string) (textsafe.Text, error)

Edit replaces the text of item n and returns the text it had. The item keeps its place.

func (Queue) Merge added in v1.0.7

func (q Queue) Merge(id state.ID, items []textsafe.Text) (MergeResult, error)

Merge adds the items that the queue lacks to its end, in the order given, and removes and reorders nothing. Items are compared by text with the rule of the JSON (trailing spaces do not count), and by number: when the queue holds "x" once and items holds it twice, one is added. It does the comparison and the appends in one hold of the lock, so that nothing added meanwhile is lost or counted twice, and it adds what fits under MaxFileBytes and says how many did not. The caller has cleaned and cut the items (MaxItem), and the change is not logged here: a bulk change is one entry, which the caller writes.

func (Queue) Move

func (q Queue) Move(from, to state.ID, n int, guard *string) (textsafe.Text, error)

Move hands item n from one queue to the end of another and returns it. The item reaches the destination before it leaves the source, so a failure can leave a duplicate but never lose it.

func (Queue) Remove

func (q Queue) Remove(id state.ID, n int, guard *string) (textsafe.Text, error)

Remove takes item n out and returns it.

func (Queue) Reorder

func (q Queue) Reorder(id state.ID, from, to int, guard *string) (textsafe.Text, error)

Reorder moves item from to position to, and returns the item.

func (Queue) Replace added in v1.0.7

func (q Queue) Replace(id state.ID, items []textsafe.Text) (before, after int, err error)

Replace makes the queue hold exactly these items, in this order, and says how many it held and how many it holds. Blank items are left out, and items past MaxFileBytes are not written (the count tells). The change is one write of the whole file under the lock. The caller has cleaned and cut the items, and the change is not logged here.

func (Queue) Texts added in v1.0.7

func (q Queue) Texts(id state.ID) []string

Texts is the items a queue holds now, as the file has them, without the empty lines. Nothing is locked, so it is a view and not a promise.

type RangeError

type RangeError struct {
	ID    state.ID
	Count int
}

RangeError says a position is past the end of the queue.

func (*RangeError) Error

func (e *RangeError) Error() string

Jump to

Keyboard shortcuts

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