Skip to content

Commit

Permalink
fix: Add resolver function directly on _commandResolves id because th…
Browse files Browse the repository at this point in the history
…ere cannot be a single instance
  • Loading branch information
samwx committed Sep 26, 2019
1 parent e051ff1 commit ae99d86
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/Lime/Protocol/Client/Channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ abstract class Channel implements MessageChannel, CommandChannel, NotificationCh
localNode: string;
sessionId: string;
state: SessionState;
_commandResolves: {};
processCommandResolver: (command: Command) => any;
_commandResolves: { [x: string]: (result?: any) => any };

constructor(transport: Transport, autoReplyPings: boolean, autoNotifyReceipt: boolean) {
this.autoReplyPings = autoReplyPings;
Expand Down Expand Up @@ -67,9 +66,8 @@ abstract class Channel implements MessageChannel, CommandChannel, NotificationCh
const responsePromise = this._commandResolves[command.id];

if (responsePromise) {
this._commandResolves[command.id](command);
delete this._commandResolves[command.id]

this.processCommandResolver(command);
return;
}
}
Expand Down Expand Up @@ -109,10 +107,9 @@ abstract class Channel implements MessageChannel, CommandChannel, NotificationCh

processCommand(command: Command, timeout = this.commandTimeout): Promise<Command> {
const responsePromise = new Promise(resolve => {
this.processCommandResolver = resolve;
this._commandResolves[command.id] = resolve;
});

this._commandResolves[command.id] = responsePromise;
const commandPromise = Promise.race([
responsePromise,
new Promise((_, reject) => {
Expand Down

0 comments on commit ae99d86

Please sign in to comment.