DurationExtension extension
An extension on the Duration class, adding asynchronous utility methods.
This extension provides simplified asynchronous operations that leverage the inherent duration specified by an instance of Duration. It offers a way to execute callback functions after a delay and a convenience getter for sleeping.
Example usage:
void main() async {
// Create a duration of 2 seconds
Duration twoSeconds = Duration(seconds: 2);
// Use the `delayed` method to execute a callback after the duration
await twoSeconds.delayed(() => print('Delayed execution'));
// Use the `sleep` getter to introduce a pause in the execution
await twoSeconds.sleep;
print('Execution resumed after sleep');
}
- on
Properties
-
sleep
→ Future<
void> -
A convenience getter that returns a Future<void> which completes after
the current duration has elapsed.
no setter