You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
964 B

import {BusQueue, Queueable, shouldQueue, ShouldQueue} from '../types'
import {Inject, Injectable} from '../../../di'
import {Awaitable, Maybe} from '../../../util'
import {Bus} from '../Bus'
import {PushingToQueue} from './event/PushingToQueue'
import {PushedToQueue} from './event/PushedToQueue'
export abstract class Queue implements BusQueue {
protected readonly bus!: Bus
public readonly name: string,
) {}
async dispatch<T extends Queueable>(item: T): Promise<void> {
if ( shouldQueue(item) ) {
await this.bus.push(new PushingToQueue(item,
await this.push(item)
await this.bus.push(new PushedToQueue(item,
await item.execute()
protected abstract push<T extends Queueable>(item: ShouldQueue<T>): Awaitable<void>
abstract pop(): Promise<Maybe<ShouldQueue<Queueable>>>