Files
taskbuffer/ts/taskbuffer.classes.taskonce.ts

22 lines
571 B
TypeScript
Raw Normal View History

2022-03-25 12:14:49 +01:00
import * as plugins from './taskbuffer.plugins.js';
2017-07-12 16:45:18 +02:00
2023-08-02 00:07:21 +02:00
import { Task, type ITaskFunction } from './taskbuffer.classes.task.js';
2017-07-12 16:45:18 +02:00
/**
* TaskOnce is run exactly once, no matter how often it is triggered
*/
export class TaskOnce extends Task {
2018-08-04 17:53:22 +02:00
hasTriggered: boolean = false;
constructor(optionsArg: { name?: string; taskFunction: ITaskFunction }) {
2017-07-12 16:45:18 +02:00
super({
name: optionsArg.name,
taskFunction: async () => {
if (!this.hasTriggered) {
2018-08-04 17:53:22 +02:00
this.hasTriggered = true;
await optionsArg.taskFunction();
2017-07-12 16:45:18 +02:00
}
2020-07-12 00:48:51 +00:00
},
2018-08-04 17:53:22 +02:00
});
2017-07-12 16:45:18 +02:00
}
2018-08-04 17:53:22 +02:00
}