Skip to content

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

Closed
@spikecurtis

Description

@spikecurtis

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions