@@ -56,9 +56,16 @@ export abstract class Emulator {
5656 const { name : tempDir } = tmp . dirSync ( { unsafeCleanup : true } ) ;
5757 const filepath = path . resolve ( tempDir , this . binaryName ) ;
5858 return new Promise < void > ( ( resolve , reject ) => {
59- // We want access to `this.binaryPath` after the download is finished, but we can't since in
60- // `readChunk`, `this` is not inherited from the parent (since it's a named function expression).
61- // To work around this, we wrap the fetch in a promise, then once it's resolved we can access `this` in the callback arrow function.
59+ /**
60+ * Once the download is `done` in `readChunk`, we want to set `this.binaryPath` to the path of the
61+ * downloaded emulator. Unfortunately, we can't access `this` when inside `readChunk`'s scope, since
62+ * it's a named function expression, and does not inherit the `this` object from it's parent.
63+ * To work around this, we wrap the fetch in a promise,
64+ * then once it's resolved we can access `this` in a callback arrow function that *does* inherit
65+ * `this` from the parent object, allowing us to set `this.binaryPath`.
66+ * Note that we can't make readChunk an arrow function, since it needs to be named so that we can
67+ * perform recursion to read the next chunk.
68+ */
6269 const downloadPromise = new Promise < Uint8Array > (
6370 ( downloadComplete , downloadFailed ) => {
6471 fetch ( this . binaryUrl )
0 commit comments