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