Send enqueues an event in a non-blocking fashion, but if the channel is full then it will block.
(ctx context.Context, payload []byte)
| 145 | // Send enqueues an event in a non-blocking fashion, but if the channel is full |
| 146 | // then it will block. |
| 147 | func (s *EventStream) Send(ctx context.Context, payload []byte) error { |
| 148 | // Save an unnecessary marshaling if possible. |
| 149 | select { |
| 150 | case <-ctx.Done(): |
| 151 | return ctx.Err() |
| 152 | case <-s.ctx.Done(): |
| 153 | return s.ctx.Err() |
| 154 | case <-s.doneCh: |
| 155 | return ErrEventStreamClosed |
| 156 | default: |
| 157 | } |
| 158 | |
| 159 | return s.SendRaw(ctx, payload) |
| 160 | } |
| 161 | |
| 162 | func (s *EventStream) SendRaw(ctx context.Context, payload []byte) error { |
| 163 | select { |
no test coverage detected