| 55 | } |
| 56 | |
| 57 | func (b *streamBridge) emit(ctx context.Context, id string, chunk pluginapi.ExecutorStreamChunk) error { |
| 58 | if b == nil || id == "" { |
| 59 | return fmt.Errorf("stream id is required") |
| 60 | } |
| 61 | b.mu.Lock() |
| 62 | chunks := b.streams[id] |
| 63 | b.mu.Unlock() |
| 64 | if chunks == nil { |
| 65 | return fmt.Errorf("stream %s is not open", id) |
| 66 | } |
| 67 | if ctx == nil { |
| 68 | ctx = context.Background() |
| 69 | } |
| 70 | select { |
| 71 | case <-ctx.Done(): |
| 72 | return ctx.Err() |
| 73 | case chunks <- chunk: |
| 74 | return nil |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func (b *streamBridge) close(id string, errorMessage string) { |
| 79 | if b == nil || id == "" { |