queue

package
v1.6.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 8 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.

View Source
var ErrNothingToAdopt = errors.New("nothing to adopt")

ErrNothingToAdopt says the session has no items, no name, no pinned Objective and no parent, and its link to the adopting session, when one was asked for, is there already.

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 Adoption added in v1.1.0

type Adoption struct {
	Items    []textsafe.Text // moved, in order
	Name     string          // the name that went to the adopting session
	NameKept string          // the name left on the other session, because the adopting one has its own
	Pin      textsafe.Text   // the pinned Objective that went to the adopting session
	PinKept  bool            // a pinned Objective left on the other session, because the adopting one has its own
	Parent   state.ID        // the parent of a Branch, whose link went to the adopting session, which had none
	// ParentKept is the parent of a Branch whose link stayed on the other session, because the adopting one has its own or is above it
	ParentKept state.ID
	Linked     bool     // the record that the other session's conversation went on as the adopting one was written (docs/ADOPT-LINK.md)
	Replaced   state.ID // the session the other one's record named before
	NotLinked  string   // why no record was written, when one was asked for and could not be

	Before int // items the adopting session held before
}

Adoption is what Adopt moved, or with dry would move.

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 ConflictError added in v1.1.0

type ConflictError struct {
	ID    state.ID
	Items int    // items it holds, when both have items
	Name  string // its name, when both have a name
	Pin   bool   // it has a pinned Objective, and so has the other
}

ConflictError says what the adopting session has already, in the places where the other session has something too. Merge keeps what it has.

func (*ConflictError) Error added in v1.1.0

func (e *ConflictError) 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 NotEndedError added in v1.1.0

type NotEndedError struct{ ID state.ID }

NotEndedError says the session to adopt from has not ended.

func (*NotEndedError) Error added in v1.1.0

func (e *NotEndedError) 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) Adopt added in v1.1.0

func (q Queue) Adopt(from, to state.ID, merge, dry bool, ended func(state.ID) bool, link func(from, to state.ID) (bool, string)) (Adoption, error)

Adopt gives the adopting session the other one's items, name and pinned Objective, in one hold of the lock. The items reach `to` before they leave `from`, so a failure can leave a duplicate but never lose one. Without merge, `to` must have nothing where `from` has something; with it, `to` keeps its own name and Objective, and the items go after its own. With dry, nothing is changed. A pinned Objective that is blank counts as none, on either session. ended, when set, is asked under the lock whether `from` has ended, so that a session resumed meanwhile is not adopted from. After an error the result lists only what did move. link, when set, asks for the record that from's conversation went on as to, written last; it is asked under the lock, and says whether to write it and, when it may not be written, why. A record that holds already is neither written nor something to adopt.

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) Put added in v1.6.2

func (q Queue) Put(id state.ID, text textsafe.Text, same func(item string) bool) (replaced bool, n int, err error)

Put replaces the first item that same says is the same as text, or else appends text, in one hold of the lock, so that two runs at once leave one item. It says whether it replaced one, and returns how many items the queue holds. The queue's folder must be there: Put makes no session.

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