You've already forked agentic-coding-workflow
feat(chat): StreamerHub with ring buffer + cond + Done/Error/Cancel flows
This commit is contained in:
@@ -15,6 +15,9 @@ type FakeClient struct {
|
||||
StreamError error // Stream() 立即返回的错误(如果非 nil)
|
||||
TokenCount int // CountTokens 返回值
|
||||
StreamCalls int
|
||||
// BlockCh, if non-nil, causes Stream goroutine to block after emitting all
|
||||
// Events until ctx is cancelled or BlockCh is closed. Useful for cancel tests.
|
||||
BlockCh chan struct{}
|
||||
}
|
||||
|
||||
// NewFake 构造一个 FakeClient,默认 provider="fake"。
|
||||
@@ -33,6 +36,8 @@ func (f *FakeClient) Stream(ctx context.Context, modelID string, req Request) (<
|
||||
events := append([]StreamEvent(nil), f.Events...)
|
||||
f.mu.Unlock()
|
||||
|
||||
blockCh := f.BlockCh
|
||||
|
||||
ch := make(chan StreamEvent, len(events)+1)
|
||||
go func() {
|
||||
defer close(ch)
|
||||
@@ -44,6 +49,14 @@ func (f *FakeClient) Stream(ctx context.Context, modelID string, req Request) (<
|
||||
case ch <- e:
|
||||
}
|
||||
}
|
||||
// If a block channel is set, pause here until ctx is cancelled or BlockCh
|
||||
// is closed. This lets cancel tests confirm mid-stream cancellation.
|
||||
if blockCh != nil {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-blockCh:
|
||||
}
|
||||
}
|
||||
}()
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user