From 801563a66c80376f64a6714c954187c9793596fe Mon Sep 17 00:00:00 2001 From: Guillaume Jenkins Date: Wed, 7 Feb 2018 12:42:55 -0500 Subject: [PATCH] Reuse the same packetio to handle suspend/resume (#634) --- editor/extension.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/editor/extension.ts b/editor/extension.ts index bab32f55..fbe90d60 100644 --- a/editor/extension.ts +++ b/editor/extension.ts @@ -75,6 +75,18 @@ namespace pxt.editor { } } + let packetIoPromise: Promise; + function initPacketIOAsync(): Promise { + if (!packetIoPromise) { + packetIoPromise = pxt.HF2.mkPacketIOAsync() + .catch(err => { + packetIoPromise = null; + return Promise.reject(err); + }); + } + return packetIoPromise; + } + let previousDapWrapper: DAPWrapper; function dapAsync() { return Promise.resolve() @@ -87,7 +99,7 @@ namespace pxt.editor { } return Promise.resolve(); }) - .then(() => pxt.HF2.mkPacketIOAsync()) + .then(() => initPacketIOAsync()) .then(h => { let w = new DAPWrapper(h) previousDapWrapper = w; @@ -327,12 +339,12 @@ namespace pxt.editor { return wrap.cortexM.reset(false) }) }) - .catch(e => { + .catch(e => { if (e.type === "devicenotfound" && d.reportDeviceNotFoundAsync) { return d.reportDeviceNotFoundAsync("/device/windows-app/troubleshoot"); } else { return saveHexAsync() - } + } }) }