Created
October 6, 2019 16:24
-
-
Save iapicca/ff00379ea419e03bf270ed9efdf9dc8e to your computer and use it in GitHub Desktop.
Domino Timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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