I build a queue of futures to ensure that those futures get completed in a sequential order, because even if one async function is called before the other this won't ensure that they get executed in this order when pushed on the event loop (my assumption).
In the UI there is a button, every time it gets pressed the async computation is pushed onto this queue. When pressed in a way that the async computation is finished before the next button press there isn't a problem but when pressed fast multiple times the computation won't finish.
In the example below every computation after job 1 won't finish.
int i = 0;
class TouchlessAlarmScheduleQueue {
Future _future = Future(() {});
addJob(String alarmId, Future<void> Function() job) {
print('$i added');
int iCopy = i;
_future = _future.then((_) {
print("$iCopy done");
return job();
});
i++;
}
}
Console Output:
flutter: 0 added
flutter: 0 done
flutter: 1 added
flutter: 2 added
flutter: 1 done
[VERBOSE-2:profiler_metrics_ios.mm(203)] Error retrieving thread information: (os/kern) invalid argument
Not sure if this profiler output is related to the problem.
