S2 take once in a bundle too, Go and TypeScript

A bundle holder takes an ask once through the runtime's create with the
ask's bound as the key's time to live: stdio.KeptState.TakeOnce and
TypeScript takeOnce; stdio.TakenState and TakenKey are the one name, which
process refers to.

Builds: design 47 H2 §775, §820; H-A-359
This commit is contained in:
2026-11-21 23:12:58 +01:00
parent 423de0e8a2
commit 25b3030a93
5 changed files with 125 additions and 14 deletions
+10 -14
View File
@@ -399,23 +399,19 @@ func (s State) delete(key string) error {
return nil
}
// TakenState is the state a holder of a kept call keeps the ids of the asks it took in (design 47 H2 §775, §820): a
// state of 8 MiB whose keys live the ask's bound and are deleted by their time to live alone, never pruned.
const TakenState = "taken"
// TakenState is the state a holder of a kept call keeps the ids of the asks it took in: stdio.TakenState.
const TakenState = stdio.TakenState
// TakenKey is the key an ask taken from seat is kept under in TakenState: `<seat>.<ask>`.
func TakenKey(seat, ask string) string { return seat + "." + ask }
// TakenKey is the key an ask taken from seat is kept under in TakenState: stdio.TakenKey.
func TakenKey(seat, ask string) string { return stdio.TakenKey(seat, ask) }
// TakeOnce says whether this holder takes the ask ask of seat now (design 47 H2 §775; ADR 0668 §2): the first time it
// is given, it is kept under TakenKey for the ask's bound and TakeOnce answers true; given again within the bound,
// false, and the holder acts once. s is the holder's TakenState, declared `key-ttl`. An ask with no id, or an id that is
// not one key, is refused: a kept call carries its id.
// TakeOnce says whether this holder takes the ask ask of seat now (design 47 H2 §775; ADR 0668 §2), as
// stdio.KeptState.TakeOnce does for a bundle: the first time it is given, it is kept under TakenKey for the ask's bound
// and TakeOnce answers true; given again within the bound, false, and the holder acts once. s is the holder's
// TakenState, declared `key-ttl`. An ask with no id, or an id that is not one key, is refused: a kept call carries its id.
func (s State) TakeOnce(seat, ask string, bound time.Duration) (bool, error) {
if err := checkAskID(ask); err != nil {
return false, fmt.Errorf("taking an ask of %s: %w", seat, err)
}
if seat == "" || strings.ContainsAny(seat, ".*> ") {
return false, fmt.Errorf("taking the ask %s: %q is not a seat's name", ask, seat)
if p := stdio.TakenProblem(seat, ask); p != "" {
return false, fmt.Errorf("taking an ask of %s: %s", seat, p)
}
_, err := s.CreateTTL(TakenKey(seat, ask), map[string]string{"seat": seat, "ask": ask}, max(bound, MinTTL))
if errors.Is(err, stdio.ErrChanged) {