Reuse the same packetio to handle suspend/resume (#634)

This commit is contained in:
Guillaume Jenkins 2018-02-07 12:42:55 -05:00 committed by GitHub
parent 442f305414
commit 801563a66c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,6 +75,18 @@ namespace pxt.editor {
} }
} }
let packetIoPromise: Promise<pxt.HF2.PacketIO>;
function initPacketIOAsync(): Promise<pxt.HF2.PacketIO> {
if (!packetIoPromise) {
packetIoPromise = pxt.HF2.mkPacketIOAsync()
.catch(err => {
packetIoPromise = null;
return Promise.reject(err);
});
}
return packetIoPromise;
}
let previousDapWrapper: DAPWrapper; let previousDapWrapper: DAPWrapper;
function dapAsync() { function dapAsync() {
return Promise.resolve() return Promise.resolve()
@ -87,7 +99,7 @@ namespace pxt.editor {
} }
return Promise.resolve(); return Promise.resolve();
}) })
.then(() => pxt.HF2.mkPacketIOAsync()) .then(() => initPacketIOAsync())
.then(h => { .then(h => {
let w = new DAPWrapper(h) let w = new DAPWrapper(h)
previousDapWrapper = w; previousDapWrapper = w;