Skip to content

Instantly share code, notes, and snippets.

@pagetronic
Created November 6, 2023 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pagetronic/f32620ec20b228c56a7fab8e7e79f37d to your computer and use it in GitHub Desktop.
Save pagetronic/f32620ec20b228c56a7fab8e7e79f37d to your computer and use it in GitHub Desktop.
import 'dart:async';
class Deferrer {
final int milliseconds;
Future? _next;
Deferrer(this.milliseconds);
void defer(void Function() toDo) {
Future? next_;
next_ = Future.delayed(Duration(milliseconds: milliseconds), () {
if (_next == next_) {
toDo();
}
});
_next = next_;
}
void abort() {
_next = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment