export default class Scheduler { public name: string private bucketMap: { [label: string]: Array } constructor(name: string) { this.name = name } subscribe(label: string, handle: Function) { if(!Array.isArray(this.bucketMap[label])) this.bucketMap[label] = [] this.bucketMap[label].push(handle) } trigger(label: string) { this.bucketMap[label].map(handle => handle()) } triggerThenFlush(label: string) { this.bucketMap[label].map(handle => handle()) this.bucketMap[label] = [] } triggerBulk(labelArray: string[]) { labelArray.map(label => this.bucketMap[label].map(handle => handle())) } }