Chronos-Swift icon indicating copy to clipboard operation
Chronos-Swift copied to clipboard

Adds OneShotTimer and OneShotDispatch Timer

Open JeanAzzopardi opened this issue 9 years ago • 3 comments

It might be a good idea to have a OneShotTimer, i.e. a timer that can only be run once after a certain delay.

I've done some refactoring to RepeatingTimer in order to change the type of the closure. , so now there are 2 closure types:

/**
The closure to execute when the timer fires.

- parameter timer:   The timer that fired.
- parameter count:   The current invocation count. The first count is 0.
*/
public typealias RepeatedExecutionClosure = ((RepeatingTimer, Int) -> Void)

/**
 The closure to execute when the timer fires.

 - parameter timer:   The timer that fired. 
 */
public typealias OneShotExecutionClosure = ((OneShotTimer) -> Void)

I realise that this is a non-trivial change, but I'd welcome any feedback.

JeanAzzopardi avatar Aug 08 '16 10:08 JeanAzzopardi

Very cool, thanks for the contribution. I wonder how much utility this would provide over dispatch_after. It could be useful for games though, especially when wanting to handle scheduled events and pausing. What were your thoughts on use cases?

Anyway, I'll be traveling through next week so I won't be able to seriously review this for a while, but overall I like the idea of including this.

comyar avatar Aug 09 '16 06:08 comyar

Thanks for your comment, I'm working on an app with multiple timers, some repeating, some one-shot (scheduled events as you said). I liked the API of Chronos, so I thought it would be great to keep the same API for one-shot timers.

JeanAzzopardi avatar Aug 09 '16 09:08 JeanAzzopardi

Sorry for the late response to this, overall it looks good. Only some minor comments throughout, really like that you also added tests and maintained the code style 😄.

I'd like to see the changes to the Timer protocol made before pulling this into master; I can make those changes if you like, otherwise you can include them in this pull request.

Regarding naming, I'm indifferent either way we go on it, I was just interested in getting your thoughts on it. Thanks again for the contribution!

comyar avatar Aug 25 '16 06:08 comyar