throttled 1.0.1 copy "throttled: ^1.0.1" to clipboard
throttled: ^1.0.1 copied to clipboard

Throttle function calls on a cooldown while ensuring the last call eventually runs with leaky calls.

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');
}

The results will print as

State pushed: 1
State pushed: 11
State pushed: 21
...
State pushed: 991
State pushed: 1000

Since leaky is turned on, the last call will eventually run.

0
likes
120
pub points
71%
popularity

Publisher

verified publisherarcane.art

Throttle function calls on a cooldown while ensuring the last call eventually runs with leaky calls.

Repository (GitHub)
View/report issues

Documentation

API reference

License

GPL-3.0 (LICENSE)

More

Packages that depend on throttled