pausable_timer icon indicating copy to clipboard operation
pausable_timer copied to clipboard

`PausableTimer` should have a method to execute the passed callback

Open Yetispapa opened this issue 1 year ago • 3 comments

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!

Yetispapa avatar Apr 12 '24 08:04 Yetispapa

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?

mateusfccp avatar Apr 12 '24 10:04 mateusfccp

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!

llucax avatar Apr 12 '24 13:04 llucax

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.

llucax avatar Apr 12 '24 13:04 llucax

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.

mateusfccp avatar Jun 24 '24 20:06 mateusfccp