Skip to content

Instantly share code, notes, and snippets.

@indatawetrust
Created August 10, 2020 06:43
Show Gist options
  • Save indatawetrust/b8354a85370a53984f39acfd5f1a3e19 to your computer and use it in GitHub Desktop.
Save indatawetrust/b8354a85370a53984f39acfd5f1a3e19 to your computer and use it in GitHub Desktop.
import 'dart:async';
Timer interval(Duration duration, func) {
Timer function() {
Timer timer = new Timer(duration, function);
func(timer);
return timer;
}
return new Timer(duration, function);
}
void main() {
int i = 0;
interval(new Duration(seconds: 1), (timer) {
print(i++);
if (i > 5) timer.cancel();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment