taskbuffer/ts/taskbuffer.classes.taskonce.ts

24 lines
563 B
TypeScript
Raw Normal View History

2017-07-12 14:45:18 +00:00
import * as plugins from './taskbuffer.plugins'
import { Task, ITaskFunction} from './taskbuffer.classes.task'
/**
* TaskOnce is run exactly once, no matter how often it is triggered
*/
export class TaskOnce extends Task {
hasTriggered: boolean = false
constructor (optionsArg: {
name?: string,
taskFunction: ITaskFunction
}) {
super({
name: optionsArg.name,
taskFunction: async () => {
if (!this.hasTriggered) {
this.hasTriggered = true
await optionsArg.taskFunction()
}
}
})
}
}