pausable_timer
pausable_timer copied to clipboard
`PausableTimer` should have a method to execute the passed callback
Hi @llucax,
Could we add a method to the PausableTimer class for directly firing the callback function, like _timer.fire();? This would be particularly useful when initializing a periodic timer and wanting to fire it immediately. I'm aware we can achieve this by creating a separate function and calling it before creating the timer and inside the timer, but having a built-in method would streamline the process.
Let me know, what you think. Thanks again!
Hello, @Yetispapa
For (1), see #48. If you feel like it's a necessity, feel free to restart the discussion there and we may reopen the issue. Because of the existing issue, I am going to edit this issue focusing on point 2.
For (2), it's really nothing technically complex, but I am afraid we may want to keep the API as similar as possible to Flutter's Timer. WDYT @llucax?
What would fire() do? Call the callback and then reset() the timer? Or it doesn't reset() the timer. Either way it looks to me that it could error prone for different users expecting different outcomes. Also, I don't remember the details, but I think the callback will run in some Runtime context, while if you called directly it might run in a different context.
My feeling is, it's not worth getting into that mess when just using a separate function as a callback and call it normally is simple enough, has very clear semantics and makes everything very obvious, but since I haven't been using Dart for years now, I might be wrong or missing something, so it is more a gut feeling that a strong technical reason, so whatever people actually using Dart now think is best, is fine with me!
Another simpler approach might be to just expose the callback via a read-ony public property, then at least is more clear that the users is just calling the call back, and the timer logic is not involved at all when the user calls the callback.
Well, as we didn't have any other response from @Yetispapa, I'm going to close this issue.
Personally, I don't think it's something necessary nor an objective improvement. You may reopen this issue if you feel like.