node-tools: a runner rereads the list only for a verb of a seat it defines, one read shared; asks of undefined seats and tools unchanged (A-490m)
Builds: design 47 G A-490m Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
This commit is contained in:
@@ -83,9 +83,10 @@ func WithSeatDefinitionsAgain(again func() error) Option {
|
||||
}
|
||||
|
||||
// chunkedAsked is chunked for a verb a bundle asks, where the answer decides whether the runner chooses the `call` the holder
|
||||
// requires (AskAsChunked): a seat verb the definitions held do not name is not taken for one that sends no chunks, since the
|
||||
// holder then refuses an ask that carries no call and the bundle sees only that refusal. The seat list is read again once, and
|
||||
// a verb it still does not name is an error that says why. A runner that holds no definitions (nil) asks no chunks.
|
||||
// requires (AskAsChunked) (design 47 G A-490m). A verb of a seat the definitions held DEFINE, whose definition does not name it,
|
||||
// is not taken for one that sends no chunks, since the holder then refuses an ask that carries no call: the seat list is read
|
||||
// again once (one read shared by the asks that wait on it) and a verb still unnamed is an error saying so. An ask of a seat the
|
||||
// definitions do not define at all, a module's tool and a runner that holds no definitions (nil) are asked as before.
|
||||
func (c *consumers) chunkedAsked(key string) (bool, error) {
|
||||
if c.definitions == nil || !strings.HasPrefix(key, "seat:") {
|
||||
return false, nil
|
||||
@@ -95,27 +96,69 @@ func (c *consumers) chunkedAsked(key string) (bool, error) {
|
||||
if !ok {
|
||||
return false, nil
|
||||
}
|
||||
find := func() (chunks, found bool) {
|
||||
for _, v := range c.definitions()[seat].Verbs {
|
||||
find := func() (chunks, defined, named bool) {
|
||||
d, defined := c.definitions()[seat]
|
||||
for _, v := range d.Verbs {
|
||||
if v.Name == verb {
|
||||
return v.Chunks, true
|
||||
return v.Chunks, true, true
|
||||
}
|
||||
}
|
||||
return false, false
|
||||
return false, defined, false
|
||||
}
|
||||
if chunks, found := find(); found {
|
||||
chunks, defined, named := find()
|
||||
if named || !defined {
|
||||
return chunks, nil
|
||||
}
|
||||
var why string
|
||||
if c.reread != nil {
|
||||
if err := c.reread(); err != nil {
|
||||
why = ": reading the seat list again failed: " + err.Error()
|
||||
if err := c.rereadShared(); err != nil {
|
||||
why = " (reading the seat list again failed: " + err.Error() + ")"
|
||||
}
|
||||
if chunks, found := find(); found {
|
||||
chunks, defined, named = find()
|
||||
if named {
|
||||
return chunks, nil
|
||||
}
|
||||
if !defined {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
return false, fmt.Errorf("the seat list this runner holds does not name the verb %s, so it cannot tell whether the verb sends its answer in chunks (the ask is not sent)%s", key, why)
|
||||
return false, fmt.Errorf("the definition of the seat %s names no verb %s, so the runner cannot tell whether it sends its answer in chunks and does not ask it%s", seat, verb, why)
|
||||
}
|
||||
|
||||
// rereadShared reads the seat list again; asks that arrive while a read runs wait for it and share its result.
|
||||
func (c *consumers) rereadShared() error {
|
||||
c.rereadMu.Lock()
|
||||
if f := c.rereading; f != nil {
|
||||
f.waiters++
|
||||
c.rereadMu.Unlock()
|
||||
<-f.done
|
||||
return f.err
|
||||
}
|
||||
f := &rereadFlight{done: make(chan struct{})}
|
||||
c.rereading = f
|
||||
c.rereadMu.Unlock()
|
||||
f.err = c.reread()
|
||||
c.rereadMu.Lock()
|
||||
c.rereading = nil
|
||||
c.rereadMu.Unlock()
|
||||
close(f.done)
|
||||
return f.err
|
||||
}
|
||||
|
||||
type rereadFlight struct {
|
||||
done chan struct{}
|
||||
err error
|
||||
waiters int // the asks that joined the read (under rereadMu)
|
||||
}
|
||||
|
||||
// rereadWaiting is how many asks have joined the read now running; a test waits on it instead of sleeping.
|
||||
func (c *consumers) rereadWaiting() int {
|
||||
c.rereadMu.Lock()
|
||||
defer c.rereadMu.Unlock()
|
||||
if c.rereading == nil {
|
||||
return 0
|
||||
}
|
||||
return c.rereading.waiters
|
||||
}
|
||||
|
||||
// chunked says whether key names a seat's verb whose definition says `chunks` (design 47 G A-249): its answer is received in
|
||||
|
||||
Reference in New Issue
Block a user