taskOnce static method

dynamic taskOnce(
  1. String name,
  2. dynamic callback()
)

Run a function once Provide a name for the function and a callback to execute. The function will only execute once.

Example:

NyScheduler.once("myFunction", () {
 print("This will only execute once");
 });

The above example will only execute once. The next time you call NyScheduler.once("myFunction", () {}) it will not execute.

Implementation

static taskOnce(String name, Function() callback) async {
  String key = name + "_once";
  bool alreadyExecuted = await readBool(key);
  if (!alreadyExecuted) {
    await writeBool(key, true);
    await callback();
  }
}