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() - } + } }) }