Skip to content

mock TickerFunc returns immediately from context cancel, even if tick function is in progress. #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spikecurtis opened this issue Oct 17, 2024 · 0 comments · Fixed by #7
Labels
bug Something isn't working

Comments

@spikecurtis
Copy link
Collaborator

The real implementation of ticker func looks like this:

func (t *realContextTicker) Wait(_ ...string) error {
	return <-t.err
}

func (t *realContextTicker) run() {
	defer t.tkr.Stop()
	for {
		select {
		case <-t.ctx.Done():
			t.err <- t.ctx.Err()
			return
		case <-t.tkr.C:
			err := t.f()
			if err != nil {
				t.err <- err
				return
			}
		}
	}
}

One property of this construction is that Wait() cannot return while t.f() is in progress, even if the context is done.

The mock ticker function doesn't share this property, and Wait() will return immediately on context done.

@coder-labeler coder-labeler bot added the bug Something isn't working label Oct 17, 2024
spikecurtis added a commit that referenced this issue Oct 18, 2024
fixes #5
fixes #6

Fixes the mock TickerFunc to behave like the real one in that it won't run more than one callback at a time and will wait until the callback completes to return from a `Wait()` call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant