Add adds an item to the batcher. It blocks until the handler has processed the item and reports the error that the handler returned. If Shutdown has been called, Add immediately returns an error.
(ctx context.Context, item any)
| 160 | // processed the item and reports the error that the handler returned. |
| 161 | // If Shutdown has been called, Add immediately returns an error. |
| 162 | func (b *Batcher) Add(ctx context.Context, item any) error { |
| 163 | c := b.AddNoWait(item) |
| 164 | // Wait until either our result is ready or the context is done. |
| 165 | select { |
| 166 | case err := <-c: |
| 167 | return err |
| 168 | case <-ctx.Done(): |
| 169 | return ctx.Err() |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | // AddNoWait adds an item to the batcher and returns immediately. When the handler is |
| 174 | // called on the item, the handler's error return value will be sent to the channel |