-
Notifications
You must be signed in to change notification settings - Fork 116
Context WithDeadline/WithTimeout methods #20
Conversation
} | ||
ctx := &timerCtx{clock: m, parent: parent, deadline: deadline, done: make(chan struct{})} | ||
propagateCancel(parent, ctx) | ||
dur := deadline.Sub(m.Now()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The core library context code uses time.Until(deadline)
but this is the same thing. Might be worth also adding a Until
method to the Clock
interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was done in #38.
@aviddiviner would you mind rebasing this and I can take a closer look? |
Do you need any help? I also really need this feature |
If you'd like to make a new PR with this rebased, that'd be great. And, have a look at the implementation and make any adjustments you'd like -- I haven't really looked yet, to be honest, so there may be issues with the approach. |
What do you think on moving these functions into subpackage? Let's say |
Closed in favor of #41. |
Thanks all. Sorry I was a bit late to respond, but I see you handled it 😊 |
Yay open source! Thanks for the contribution :D |
Hi. I don't know what you think of this, but I make heavy use of contexts in my code and I needed to test some timeouts using the mock clock. So I added on two methods to the
Clock
interface, as well as their mock implementations (inspired from the core librarycontext.WithDeadline
code).Let me know what you think, I'm happy to tweak things. Of course, we can also add tests, etc.