waitForSequence blocks up to maxWaitTime until the given sequence has been received.
(ctx context.Context, sequence uint64, maxWaitTime time.Duration)
| 1046 | |
| 1047 | // waitForSequence blocks up to maxWaitTime until the given sequence has been received. |
| 1048 | func (c *changeCache) waitForSequence(ctx context.Context, sequence uint64, maxWaitTime time.Duration) error { |
| 1049 | startTime := time.Now() |
| 1050 | |
| 1051 | worker := func() (bool, error, interface{}) { |
| 1052 | if c.getNextSequence() >= sequence+1 { |
| 1053 | base.DebugfCtx(ctx, base.KeyCache, "waitForSequence(%d) took %v", sequence, time.Since(startTime)) |
| 1054 | return false, nil, nil |
| 1055 | } |
| 1056 | // retry |
| 1057 | return true, nil, nil |
| 1058 | } |
| 1059 | |
| 1060 | ctx, cancel := context.WithDeadline(ctx, startTime.Add(maxWaitTime)) |
| 1061 | sleeper := base.SleeperFuncCtx(base.CreateMaxDoublingSleeperFunc(math.MaxInt64, 1, 100), ctx) |
| 1062 | err, _ := base.RetryLoop(ctx, fmt.Sprintf("waitForSequence(%d)", sequence), worker, sleeper) |
| 1063 | cancel() |
| 1064 | return err |
| 1065 | } |
| 1066 | |
| 1067 | // waitForSequenceNotSkipped blocks up to maxWaitTime until the given sequence has been received or skipped. |
| 1068 | func (c *changeCache) waitForSequenceNotSkipped(ctx context.Context, sequence uint64, maxWaitTime time.Duration) error { |