Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AlarmChallengeController extends GetxController {
AlarmModel alarmRecord = Get.arguments;

final RxDouble progress = 1.0.obs;
int _timerSessionId = 0;

final RxInt shakedCount = 0.obs;
final isShakeOngoing = Status.initialized.obs;
Expand Down Expand Up @@ -204,7 +205,15 @@ class AlarmChallengeController extends GetxController {
const totalIterations = 1500000;
const decrement = 0.000001;

// Capture the current session ID for this specific async loop
final int currentSessionId = _timerSessionId;

for (var i = totalIterations; i > 0; i--) {
// If the global session ID has changed, kill this orphaned loop immediately
if (currentSessionId != _timerSessionId) {
break;
}

if (!isTimerEnabled) {
debugPrint('THIS IS THE BUG');
break;
Expand All @@ -220,10 +229,36 @@ class AlarmChallengeController extends GetxController {
}

restartTimer() {
_timerSessionId++; // Increment ID to kill any existing async loops
progress.value = 1.0; // Reset the progress to its initial value
_startTimer(); // Start a new timer
}

// void _startTimer() async {
// const duration = Duration(seconds: 15);
// const totalIterations = 1500000;
// const decrement = 0.000001;

// for (var i = totalIterations; i > 0; i--) {
// if (!isTimerEnabled) {
// debugPrint('THIS IS THE BUG');
// break;
// }
// if (progress.value <= 0.0) {
// shouldProcessStepCount = false;
// Get.until((route) => route.settings.name == '/alarm-ring');
// break;
// }
// await Future.delayed(duration ~/ i);
// progress.value -= decrement;
// }
// }

// restartTimer() {
// progress.value = 1.0; // Reset the progress to its initial value
// _startTimer(); // Start a new timer
// }

isChallengesComplete() {
if (!Utils.isChallengeEnabled(alarmRecord)) {
isNumMathQuestionsSet = false;
Expand Down