Skip to content

Instantly share code, notes, and snippets.

@iapicca
Created October 6, 2019 16:24
Show Gist options
  • Save iapicca/ff00379ea419e03bf270ed9efdf9dc8e to your computer and use it in GitHub Desktop.
Save iapicca/ff00379ea419e03bf270ed9efdf9dc8e to your computer and use it in GitHub Desktop.
Domino Timer
import 'dart:async';
class Singleton {
static final _instance = Singleton._internal();
factory Singleton() => _instance;
Singleton._internal() {}
Duration _delay = Duration();
Timer _reset;
void _timeout() => _delay = Duration();
Duration delay(Duration duration) {
if(_reset== null||!_reset.isActive) {
_reset = Timer(duration,_timeout,);
}
return _delay+=duration;
}
}
void main() async {
const Duration _duration = Duration(milliseconds:200);
final Singleton _singleton = Singleton();
for(int i=1;i <= 10;i++){
await Future.delayed(_singleton.delay(_duration));
print(i.toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment