-
I try to have a simple timer and need to pause it: late final PausableTimer timer;
now I want to pause it:
But after starting again with How can I restart the timer from the exact position where i paused it? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hi @desmeit, I'm not sure why are you observing this behaviour, it might be useful to provide a full test case to reproduce it. The timer should continue from where it was paused, have a look at the source code: pausable_timer/lib/pausable_timer.dart Line 63 in d7253c1 This is also being tested in the tests: pausable_timer/test/pausable_timer_test.dart Lines 79 to 121 in d7253c1 If there is really a bug, I won't be able to look at it sadly, as I haven't worked with Dart for years now, I don't even have Dart installed anymore. I'm looking for a maintainer to take over. |
Beta Was this translation helpful? Give feedback.
-
Can you please try out this example and let me know if it works or not for you? https://github.com/llucax/pausable_timer/blob/main/example/countdown.dart |
Beta Was this translation helpful? Give feedback.
-
BTW, I will convert to a discussion until we can confirm this is a bug. |
Beta Was this translation helpful? Give feedback.
-
@desmeit I just found my $ dart --version
Dart SDK version: 3.0.2 (stable) (Tue May 23 08:26:58 2023 +0000) on "linux_x64"
$ git diff | cat
diff --git a/example/countdown.dart b/example/countdown.dart
index c26429e..0eb1ea7 100644
--- a/example/countdown.dart
+++ b/example/countdown.dart
@@ -27,10 +27,10 @@ void main() async {
},
)..start();
- print('And wait 2.1 seconds...');
+ print('And wait 2.5 seconds...');
print('(0.1 extra to make sure there is no race between the timer and the '
'waiting here)');
- await Future<void>.delayed(timer.duration * 2.1);
+ await Future<void>.delayed(timer.duration * 2.5);
print('By now 2 events should have fired: 4, 3\n');
print('We can pause it now');
$ dart countdown.dart | while read l; do echo "$(date +'%T.%N' | cut -c-11) $l"; done
14:16:06.86 Create a periodic timer that fires every 1 second and starts it
14:16:06.87 And wait 2.5 seconds...
14:16:06.87 (0.1 extra to make sure there is no race between the timer and the waiting here)
14:16:07.89 4
14:16:08.89 3 <----------------------------- LAST TICK AT ~8.9
14:16:09.38 By now 2 events should have fired: 4, 3
14:16:09.39
14:16:09.40 We can pause it now <--------- PAUSED AT 9.4 (0.5 seconds after the last tick)
14:16:09.41 And we wait for 2 more seconds... <---- 2 SECONDS Paused
14:16:11.38 But our timer doesn't care while it's paused
14:16:11.39
14:16:11.40 So we start it again <-------- RESUMED AT 11.4
14:16:11.41 And wait for 3.1 seconds more...
14:16:11.89 2 <------------------ NEXT TICK AT 11.9 (0.5 seconds after resumed)
14:16:12.89 1
14:16:13.89 0
14:16:14.48 And we are done: 2, 1 and 0 should have been printed
14:16:14.49 The timer should be unpaused, inactive, expired and not cancelled
14:16:14.50 isPaused: false
14:16:14.51 isActive: false
14:16:14.52 isExpired: true
14:16:14.53 isCancelled: false
14:16:14.54 We can now reset it and start it again, now for 3 seconds
14:16:14.55 And wait for 3.1 seconds...
14:16:15.49 2
14:16:16.49 1
14:16:17.49 0
14:16:17.59 And it should be done printing: 2, 1 and 0 As you can see, the timer is resumed where it was left when paused. |
Beta Was this translation helpful? Give feedback.
-
okay thanks, maybe I made a mistake. |
Beta Was this translation helpful? Give feedback.
@desmeit I just found my
dart
environment I use to make releases and tried the countdown example (with a small modification to make it more obvious) which pauses the timer and it works fine: