Send enqueues an event in a non-blocking fashion, but if the channel is full then it will block.
(ctx context.Context, payload []byte)
| 163 | // Send enqueues an event in a non-blocking fashion, but if the channel is full |
| 164 | // then it will block. |
| 165 | func (s *EventStream) Send(ctx context.Context, payload []byte) error { |
| 166 | // Save an unnecessary marshaling if possible. |
| 167 | select { |
| 168 | case <-ctx.Done(): |
| 169 | return ctx.Err() |
| 170 | case <-s.ctx.Done(): |
| 171 | return s.ctx.Err() |
| 172 | case <-s.doneCh: |
| 173 | return ErrEventStreamClosed |
| 174 | default: |
| 175 | } |
| 176 | |
| 177 | return s.SendRaw(ctx, payload) |
| 178 | } |
| 179 | |
| 180 | func (s *EventStream) SendRaw(ctx context.Context, payload []byte) error { |
| 181 | select { |
no test coverage detected