taskbuffer/ts/taskbuffer.classes.taskonce.ts

22 lines
566 B
TypeScript
Raw Permalink 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
2022-03-25 11:14:49 +00:00
import { Task, 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
}