taskbuffer/ts/taskbuffer.classes.taskonce.ts
2023-08-02 00:07:21 +02:00

22 lines
571 B
TypeScript

import * as plugins from './taskbuffer.plugins.js';
import { Task, type ITaskFunction } from './taskbuffer.classes.task.js';
/**
* TaskOnce is run exactly once, no matter how often it is triggered
*/
export class TaskOnce extends Task {
hasTriggered: boolean = false;
constructor(optionsArg: { name?: string; taskFunction: ITaskFunction }) {
super({
name: optionsArg.name,
taskFunction: async () => {
if (!this.hasTriggered) {
this.hasTriggered = true;
await optionsArg.taskFunction();
}
},
});
}
}