Documentation
¶
Index ¶
- func FirstLine(s string) string
- func HasTag(tags []string, want string) bool
- func IsParked(t *store.Task) bool
- func LaunchKeys(taskID, resume string) []string
- func LaunchResumeKey(resume string) string
- func LaunchTaskKey(taskID string) string
- func WriteJSON(w http.ResponseWriter, code int, v any)
- func WriteJSONErr(w http.ResponseWriter, code int, err error)
- type ErrString
- type KeyedMutex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LaunchKeys ¶
LaunchKeys is the set of locks a launch or restart must hold across its check-then-spawn region: the card it lands on, and the conversation it resumes. Either may be empty, which drops out of the set.
func LaunchResumeKey ¶
func LaunchTaskKey ¶
LaunchTaskKey and LaunchResumeKey namespace the two kinds of key so a card id and a resume id that happen to be the same string cannot collide on one lock.
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, code int, v any)
WriteJSON answers code with v as JSON.
func WriteJSONErr ¶
func WriteJSONErr(w http.ResponseWriter, code int, err error)
Types ¶
type ErrString ¶
type ErrString string
ErrString is an error from a literal, without reaching for fmt.
type KeyedMutex ¶
type KeyedMutex struct {
// contains filtered or unexported fields
}
KeyedMutex serializes work that shares a key.
It is the lock that makes a launch's check-then-spawn region atomic against another caller. `launch.go` reads whether a runner is live on a card, or whether a conversation is already resumed somewhere, and only afterwards spawns and registers the process that would change those answers. Two callers racing through that gap both see "not live" and both spawn onto the one conversation, which is the braided-transcript corruption launch.go's own comments warn about. Holding this across the gap closes it.
A mutex is created on first use and kept. The keys are card ids and resume ids, a bounded set, so a handful of idle mutexes left behind cost nothing and buy a design with no reference counting to get wrong.
func NewKeyedMutex ¶
func NewKeyedMutex() *KeyedMutex
func (*KeyedMutex) HeldKey ¶
func (k *KeyedMutex) HeldKey() string
HeldKey is a key whose mutex is held now, or "".
func (*KeyedMutex) Lock ¶
func (k *KeyedMutex) Lock(keys ...string) func()
Lock takes every key's mutex and returns the release.
SORTED AND DEDUPED, which is the whole reason a caller passes the set at once rather than locking one key and then another. Two callers asking for the same two keys in the opposite order would deadlock, each holding the one the other wants; a single sorted acquisition order removes that. An empty set is a valid no-op, so a plain launch that names neither a card nor a resume is not serialized against anything.
func (*KeyedMutex) TryLock ¶ added in v0.0.4
func (k *KeyedMutex) TryLock(keys ...string) (func(), bool)
TryLock takes every key's mutex without waiting, or none of them and false.