| 32 | } |
| 33 | |
| 34 | func (b *streamBridge) open(ctx context.Context) (string, <-chan pluginapi.ExecutorStreamChunk, func()) { |
| 35 | if b == nil { |
| 36 | chunks := make(chan pluginapi.ExecutorStreamChunk) |
| 37 | close(chunks) |
| 38 | return "", chunks, func() {} |
| 39 | } |
| 40 | id := strconv.FormatUint(b.next.Add(1), 10) |
| 41 | chunks := make(chan pluginapi.ExecutorStreamChunk, 16) |
| 42 | b.mu.Lock() |
| 43 | b.streams[id] = chunks |
| 44 | b.mu.Unlock() |
| 45 | cleanup := func() { |
| 46 | b.close(id, "") |
| 47 | } |
| 48 | if ctx != nil && ctx.Done() != nil { |
| 49 | go func() { |
| 50 | <-ctx.Done() |
| 51 | b.close(id, ctx.Err().Error()) |
| 52 | }() |
| 53 | } |
| 54 | return id, chunks, cleanup |
| 55 | } |
| 56 | |
| 57 | func (b *streamBridge) emit(ctx context.Context, id string, chunk pluginapi.ExecutorStreamChunk) error { |
| 58 | if b == nil || id == "" { |