BlockSoonWaiter returns a channel that waits for the block at the given height, but it is an error to wait for a block far in the future. WaitForBlockSoon will timeout if the context times out. To wait unconditionally, the caller should use WaitForBlock.
(ctx context.Context, height uint64)
| 184 | // WaitForBlockSoon will timeout if the context times out. |
| 185 | // To wait unconditionally, the caller should use WaitForBlock. |
| 186 | func (c *Chain) BlockSoonWaiter(ctx context.Context, height uint64) <-chan error { |
| 187 | ch := make(chan error, 1) |
| 188 | |
| 189 | go func() { |
| 190 | const slop = 3 |
| 191 | if height > c.Height()+slop { |
| 192 | ch <- ErrTheDistantFuture |
| 193 | return |
| 194 | } |
| 195 | |
| 196 | select { |
| 197 | case <-c.BlockWaiter(height): |
| 198 | ch <- nil |
| 199 | case <-ctx.Done(): |
| 200 | ch <- ctx.Err() |
| 201 | } |
| 202 | }() |
| 203 | |
| 204 | return ch |
| 205 | } |
| 206 | |
| 207 | // BlockWaiter returns a channel that |
| 208 | // waits for the block at the given height. |