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
- Variables
- func Fits(items []textsafe.Text) int
- func Label(id state.ID) string
- func LabelFor(st state.Store, id state.ID) string
- func Missing(have []string, items []textsafe.Text) (add []textsafe.Text, skipped int)
- func MissingAt(have []string, items []textsafe.Text) (idx []int, skipped int)
- type ChangedError
- type MergeResult
- type NoItemError
- type Queue
- func (q Queue) Add(id state.ID, text textsafe.Text) (int, error)
- func (q Queue) Count(id state.ID) int
- func (q Queue) Edit(id state.ID, n int, text textsafe.Text, guard *string) (textsafe.Text, error)
- func (q Queue) Merge(id state.ID, items []textsafe.Text) (MergeResult, error)
- func (q Queue) Move(from, to state.ID, n int, guard *string) (textsafe.Text, error)
- func (q Queue) Remove(id state.ID, n int, guard *string) (textsafe.Text, error)
- func (q Queue) Reorder(id state.ID, from, to int, guard *string) (textsafe.Text, error)
- func (q Queue) Replace(id state.ID, items []textsafe.Text) (before, after int, err error)
- func (q Queue) Texts(id state.ID) []string
- type RangeError
Constants ¶
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.
const MaxItem = 200
MaxItem is the longest item, in characters.
Variables ¶
var ErrBlank = errors.New("nothing to queue")
ErrBlank says the text to queue holds nothing.
var ErrEmpty = errors.New("queue empty")
ErrEmpty says the queue has no items.
var ErrFull = errors.New("queue full: remove some items first")
ErrFull says a queue file has reached MaxFileBytes.
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
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 ¶
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
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
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.
Types ¶
type ChangedError ¶
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 ¶
NoItemError says there is no item at that position.
func (*NoItemError) Error ¶
func (e *NoItemError) Error() string
type Queue ¶
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) Edit ¶ added in v0.6.0
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
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 ¶
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) Replace ¶ added in v1.0.7
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.
type RangeError ¶
RangeError says a position is past the end of the queue.
func (*RangeError) Error ¶
func (e *RangeError) Error() string