MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / read

Method read

internal/pluginhost/model_stream_bridge.go:47–78  ·  view source on GitHub ↗
(ctx context.Context, id string)

Source from the content-addressed store, hash-verified

45}
46
47func (b *modelStreamBridge) read(ctx context.Context, id string) (handlers.ModelExecutionChunk, bool, error) {
48 if b == nil {
49 return handlers.ModelExecutionChunk{}, true, fmt.Errorf("model stream bridge is unavailable")
50 }
51 if id == "" {
52 return handlers.ModelExecutionChunk{}, true, fmt.Errorf("model stream id is required")
53 }
54 b.mu.Lock()
55 entry, ok := b.streams[id]
56 b.mu.Unlock()
57 if !ok || entry.chunks == nil {
58 return handlers.ModelExecutionChunk{}, true, nil
59 }
60 if ctx == nil {
61 ctx = context.Background()
62 }
63 select {
64 case <-ctx.Done():
65 b.close(id)
66 return handlers.ModelExecutionChunk{}, true, ctx.Err()
67 case chunk, okRead := <-entry.chunks:
68 if !okRead {
69 b.close(id)
70 return handlers.ModelExecutionChunk{}, true, nil
71 }
72 if chunk.Err != nil {
73 b.close(id)
74 return chunk, true, nil
75 }
76 return chunk, false, nil
77 }
78}
79
80func (b *modelStreamBridge) close(id string) {
81 if b == nil || id == "" {

Callers 2

Calls 1

closeMethod · 0.95

Tested by

no test coverage detected