taskbuffer/ts/taskbuffer.classes.taskonce.ts

22 lines
560 B
TypeScript
Raw Normal View History

2018-08-04 17:53:22 +02:00
import * as plugins from './taskbuffer.plugins';
2017-07-12 16:45:18 +02:00
2018-08-04 17:53:22 +02:00
import { Task, ITaskFunction } from './taskbuffer.classes.task';
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
}