jonboulle / clockwork

a fake clock for golang
Apache License 2.0
625 stars 57 forks source link

Add a WithSynchronousAfterFunc option #68

Closed MichaelSnowden closed 11 months ago

MichaelSnowden commented 1 year ago

This is for https://github.com/jonboulle/clockwork/issues/67

I'm happy to add more context if you'd like, but the main idea is that this makes it a lot easier to test certain things. For example, if you want to verify that a timer did fire without this option, you could just block for a while and wait for it to return. However, if you wanted to verify that timer did not fire, you'd have to set an arbitrary wait amount.

DPJacques commented 11 months ago

Take a look at #69 . I think we can find a way meet your needs without adding dimensionality to the behavior of FakeClock

MichaelSnowden commented 11 months ago

Take a look at #69 . I think we can find a way meet your needs without adding dimensionality to the behavior of FakeClock

Hmm, how would you do something like the TestFakeClockSynchronousAfterFunc test I have here with the Expirations() and BlockUntilContext() APIs? I think you can be sure that the function started, but, for my use case, I still need some indication that whatever timer callback there was finished. I think something more like Flush(ctx) which blocks until all channels are sent to and all callbacks are done would be better.