Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'users/t-anmah/debugger' of https://github.com/microsoft…
Browse files Browse the repository at this point in the history
…/vscode-python-devicesimulator into users/t-anmah/debugger
  • Loading branch information
andreamah committed Feb 24, 2020
2 parents 79187f4 + 997cf2a commit 78821fb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/debuggerCommunicationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class DebuggerCommunicationServer {
private serverIo: socketio.Server;
private simulatorWebview: WebviewPanel | undefined;
private currentActiveDevice;
private isWaitingResponse = false;
private currentCall: Array<Function> = [];
private isPendingResponse = false;
private pendingCallbacks: Array<Function> = [];

constructor(
webviewPanel: WebviewPanel | undefined,
Expand Down Expand Up @@ -54,22 +54,21 @@ export class DebuggerCommunicationServer {
public setWebview(webviewPanel: WebviewPanel | undefined) {
this.simulatorWebview = webviewPanel;
}

// Events are pushed when the previous processed event is over
public emitInputChanged(newState: string): void {
if (this.isWaitingResponse) {
this.currentCall.push(() => {
if (this.isPendingResponse) {
this.pendingCallbacks.push(() => {
this.serverIo.emit(
DEBUGGER_MESSAGES.EMITTER.INPUT_CHANGED,
newState
);
this.isWaitingResponse = true;
});
} else {
this.serverIo.emit(
DEBUGGER_MESSAGES.EMITTER.INPUT_CHANGED,
newState
);
this.isWaitingResponse = true;
this.isPendingResponse = true;
}
}

Expand All @@ -90,10 +89,12 @@ export class DebuggerCommunicationServer {
);
});
socket.on(DEBUGGER_MESSAGES.LISTENER.RECEIVED_STATE, () => {
this.isWaitingResponse = false;
if (this.currentCall.length > 0) {
let currentCall = this.currentCall.shift();
if (this.pendingCallbacks.length > 0) {
const currentCall = this.pendingCallbacks.shift();
currentCall();
this.isPendingResponse = true;
} else {
this.isPendingResponse = false;
}
});

Expand Down

0 comments on commit 78821fb

Please sign in to comment.