UNPKG

@jaenster/queues

Version:
19 lines (14 loc) 439 B
import {Work} from "./work.js"; import {FiFo} from "../queue/fi-fo.js"; export abstract class WorkQueued<T> { protected queue: FiFo<T> = new FiFo(Work.queue.add.bind(Work.queue, this)); public send(...t: T[]) { this.queue.add(...t); } protected abstract handle(t: T): void protected work() { while (this.queue.has()) { this.handle(this.queue.next()); } } }