1package structs
2
3// BatchFuture is used to wait on a batch update to complete
4type BatchFuture struct {
5	doneCh chan struct{}
6	err    error
7	index  uint64
8}
9
10// NewBatchFuture creates a new batch future
11func NewBatchFuture() *BatchFuture {
12	return &BatchFuture{
13		doneCh: make(chan struct{}),
14	}
15}
16
17// Wait is used to block for the future to complete and returns the error
18func (b *BatchFuture) Wait() error {
19	<-b.doneCh
20	return b.err
21}
22
23// WaitCh is used to block for the future to complete
24func (b *BatchFuture) WaitCh() <-chan struct{} {
25	return b.doneCh
26}
27
28// Error is used to return the error of the batch, only after Wait()
29func (b *BatchFuture) Error() error {
30	return b.err
31}
32
33// Index is used to return the index of the batch, only after Wait()
34func (b *BatchFuture) Index() uint64 {
35	return b.index
36}
37
38// Respond is used to unblock the future
39func (b *BatchFuture) Respond(index uint64, err error) {
40	b.index = index
41	b.err = err
42	close(b.doneCh)
43}
44