Skip to content

Commit

Permalink
com: avoid redundent forwarding of messages (#500)
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanYarik authored Nov 10, 2020
1 parent d0a78ec commit 225a1c0
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/core/src/com/communication.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
CALLBACK_TIMEOUT,
DUPLICATE_REGISTER,
MISSING_ENV,
REMOTE_CALL_FAILED,
reportError,
UNKNOWN_CALLBACK_ID,
} from './errors';
import { CALLBACK_TIMEOUT, DUPLICATE_REGISTER, REMOTE_CALL_FAILED, reportError, UNKNOWN_CALLBACK_ID } from './errors';
import { isWindow, isWorkerContext, MultiCounter } from './helpers';
import type {
CallbackMessage,
Expand Down Expand Up @@ -520,14 +513,10 @@ export class Communication {
}
}
private sendTo(envId: string, message: Message): void {
const start = this.resolveMessageTarget(envId);
if (!start) {
throw new Error(MISSING_ENV(envId, Object.keys(this.environments)));
}
if (this.pendingEnvs.get(envId)) {
this.pendingMessages.add(envId, () => this.post(start, message));
this.pendingMessages.add(envId, () => this.post(this.resolveMessageTarget(envId), message));
} else {
this.post(start, message);
this.post(this.resolveMessageTarget(envId), message);
}
}

Expand Down

0 comments on commit 225a1c0

Please sign in to comment.