Fixed async emits overrunning each other causing no-running-subscriber errors.
This commit is contained in:
parent
97b041f1a0
commit
7c37182d03
@ -375,7 +375,7 @@ export class AbstractProvider implements Provider {
|
||||
this.#plugins = new Map();
|
||||
this.#pausedState = null;
|
||||
|
||||
this.#nextTimer = 0;
|
||||
this.#nextTimer = 1;
|
||||
this.#timers = new Map();
|
||||
|
||||
this.#disableCcipRead = false;
|
||||
@ -1161,7 +1161,9 @@ export class AbstractProvider implements Provider {
|
||||
|
||||
async emit(event: ProviderEvent, ...args: Array<any>): Promise<boolean> {
|
||||
const sub = await this.#hasSub(event, args);
|
||||
if (!sub) { return false; };
|
||||
// If there is not subscription or if a recent emit removed
|
||||
// the last of them (which also deleted the sub) do nothing
|
||||
if (!sub || sub.listeners.length === 0) { return false; };
|
||||
|
||||
const count = sub.listeners.length;
|
||||
sub.listeners = sub.listeners.filter(({ listener, once }) => {
|
||||
|
@ -56,6 +56,9 @@ export class PollingBlockSubscriber implements Subscriber{
|
||||
return;
|
||||
}
|
||||
|
||||
// We have been stopped
|
||||
if (this.#poller == null) { return; }
|
||||
|
||||
// @TODO: Put a cap on the maximum number of events per loop?
|
||||
|
||||
if (blockNumber !== this.#blockNumber) {
|
||||
@ -71,8 +74,8 @@ export class PollingBlockSubscriber implements Subscriber{
|
||||
|
||||
start(): void {
|
||||
if (this.#poller) { throw new Error("subscriber already running"); }
|
||||
this.#poll();
|
||||
this.#poller = this.#provider._setTimeout(this.#poll.bind(this), this.#interval);
|
||||
this.#poll();
|
||||
}
|
||||
|
||||
stop(): void {
|
||||
|
Loading…
Reference in New Issue
Block a user