API Reference 1.0.1+1rikulo_async

rikulo_async library


void defer(key, void task(), {Duration min: const Duration(seconds:1), Duration max}) #

Defers the execution of a task. If the key is the same, the task in the second invocation will override the previous. In other words, the previous task is canceled.

It is useful if you have a task that happens frequently but you prefer not to execute them all but only the once for a while (because of costly). For example,

defer("cur.task", () {
  currentUser.save(["task"]); //a costly operation
}, min: const Duration(seconds: 1), max: const Duration(seconds: 10));
//then, it executes not faster than once per 10s,
//and no later than 100s
  • key - used to identify task. If key is the same, we consider the task is the same. If different, they are handled separately.

  • min - specifies the minimal duration that the given task will be executed. In short, the task will be invoked min milliseconds later if no following invocation with the same key.

  • max - specifies the maximal duration that the given task will be executed. If given (i.e., not null), task will be execute at least max milliseconds later even if there are following invocations with the same key.

void defer(key, void task(), {Duration min: const Duration(seconds: 1), Duration max}) {
 _deferrer.run(key, task, min, max);

Abstract Classes