feed: inline handlers, remove FeedBlockingRead wrapper
This commit is contained in:
parent
721b49ffa2
commit
1537e35685
|
|
@ -680,19 +680,11 @@ func (ag *Agent) FeedWrite(data []byte) {
|
|||
ag.notifyChange()
|
||||
}
|
||||
|
||||
// FeedBlockingRead blocks until feed data differs from base.
|
||||
// Returns the data and a nextBase for the caller to use on the next call.
|
||||
// This is the same function used by both the 9P BlockOnce handler and
|
||||
// the internal consumer goroutine.
|
||||
func (ag *Agent) FeedBlockingRead(ctx context.Context, base string) ([]byte, string, error) {
|
||||
_, ok := ag.WaitChange(ctx, WatchFeed, base)
|
||||
if !ok {
|
||||
return nil, base, ctx.Err()
|
||||
}
|
||||
data := ag.feed.Get()
|
||||
hash := ag.feed.Hash()
|
||||
return data, hash, nil
|
||||
}
|
||||
// FeedGet returns the current feed data.
|
||||
func (ag *Agent) FeedGet() []byte { return ag.feed.Get() }
|
||||
|
||||
// FeedHash returns the current feed content hash.
|
||||
func (ag *Agent) FeedHash() string { return ag.feed.Hash() }
|
||||
|
||||
// StartFeedConsumer spawns a goroutine that blocks on feed changes and
|
||||
// submits new data as prompts. Exits when ctx is cancelled.
|
||||
|
|
@ -700,14 +692,15 @@ func (ag *Agent) StartFeedConsumer(ctx context.Context) {
|
|||
go func() {
|
||||
var base string
|
||||
for {
|
||||
data, nextBase, err := ag.FeedBlockingRead(ctx, base)
|
||||
if err != nil {
|
||||
_, ok := ag.WaitChange(ctx, WatchFeed, base)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
data := ag.feed.Get()
|
||||
base = ag.feed.Hash()
|
||||
if len(data) == 0 {
|
||||
continue
|
||||
}
|
||||
base = nextBase
|
||||
ag.Submit(ctx, string(data))
|
||||
ag.EnsureTrailingNewline()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -397,24 +397,22 @@ func buildAgentChildren(a *agent.Agent, s *session.Session) []virtfs.FsNodeDecl
|
|||
if len(data) == 0 {
|
||||
return nil
|
||||
}
|
||||
// Skip NUL-only input.
|
||||
allNul := true
|
||||
for _, b := range data {
|
||||
if b != 0 {
|
||||
allNul = false
|
||||
break
|
||||
a.FeedWrite(data)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if allNul {
|
||||
return nil
|
||||
}
|
||||
a.FeedWrite(data)
|
||||
return nil
|
||||
}),
|
||||
virtfs.BlockOnce(func(cctx context.Context, base string) ([]byte, string, error) {
|
||||
merged, cancel := mergeCtx(s.Ctx, cctx)
|
||||
defer cancel()
|
||||
return a.FeedBlockingRead(merged, base)
|
||||
_, ok := a.WaitChange(merged, agent.WatchFeed, base)
|
||||
if !ok {
|
||||
return nil, base, merged.Err()
|
||||
}
|
||||
return a.FeedGet(), a.FeedHash(), nil
|
||||
}),
|
||||
),
|
||||
virtfs.FileNode("chat", 0444,
|
||||
|
|
|
|||
Loading…
Reference in New Issue