taskbuffer/ts/taskbuffer.classes.taskonce.ts

22 lines
571 B
TypeScript
Raw Normal View History

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