-
Notifications
You must be signed in to change notification settings - Fork 134
Open
Description
I am trying to make a version of the pubsub async iterator that throws an error if the pushQueue goes over a certain size. Right now it is difficult to extend the existing pubsub async iterator to add this because most things are set to private and cannot be accessed by an overriding class.
Right now I am having to do this:
class MaxQueuePubSubAsyncIterator<T> extends PubSubAsyncIterator<T> {
constructor(pubsub: PubSubEngine, eventNames: string | string[]) {
super(pubsub, eventNames)
// pushValue and pushQueue are private so this is a hack to access/override them.
const super_pushValue = this["pushValue"] as ((event:T) => Promise<void>)
this["pushValue"] = async (event: T) => {
if ((this["pushQueue"] as T[]).length >= MAX_QUEUE) {
throw new MaxQueueError('Maximum Queue Size Reached')
}
return await super_pushValue(event)
}
}
}
However if pushValue
and pushQueue
were marked as protected instead of private, they would still be inaccessible in normal usage but could be accessed from extending classes and simplify this code quite a bit:
class MaxQueuePubSubAsyncIterator<T> extends PubSubAsyncIterator<T> {
override async pushValue(event: T) {
if (this.pushQueue.length >= MAX_QUEUE) {
throw new MaxQueueError('Maximum Queue Size Reached')
}
return super.pushValue(event)
}
}
Metadata
Metadata
Assignees
Labels
No labels