throttled

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

throttled

Throttle function calls with the ability to ensure the last trigger will eventually call the callback (leaky)
Features #
Throttle functions are not delays, they work like cooldowns. Calling it once happens immediately, calling it again will within the cooldown will not trigger the callback. Calling it again after the cooldown will trigger the callback again. The last call will always trigger the callback after the delay if leaky is set to true.
Usage #
Given the example
import 'package:throttle/throttle.dart';

int state = 0;

Future<void> run() async
{
while(state < 1000) {
await Future.delayted(Duration(milliseconds: 100), () {});
state++;
throttle(() => updateState(),
cooldown: Duration(seconds: 1),
leaky: true);
}
}

void updateState(){
print('State pushed: $state');
}
copied to clipboard
The results will print as
State pushed: 1
State pushed: 11
State pushed: 21
...
State pushed: 991
State pushed: 1000
copied to clipboard
Since leaky is turned on, the last call will eventually run.

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.