-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shim in a different function to run the init generator to completion
When I tried to use the existing module within a Webpack project I found that the generator was continuing with promises and trying to initialize WebAssembly using them, which obviously failed. This function seems to work a lot better for some reason, although I haven't digged into why, exactly.
- Loading branch information
Showing
3 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Note: this function comes from https://stackoverflow.com/questions/30401486/ecma6-generators-yield-promise. | ||
// It is used to convert a generator function into a promise. | ||
// `jco transpile` generates a similar function but it didn't work for me. | ||
// I'm not sure why, but I'll raise an issue on the `jco` repo. | ||
// See the `justfile` for how this gets shimmed into the transpiled code; | ||
// in short, we use `ripgrep` as in | ||
// https://unix.stackexchange.com/questions/181180/replace-multiline-string-in-files | ||
// (it was a Stack-Overflow heavy day...) | ||
// The indentation is intentional so the function matches the original. | ||
function run(g) { | ||
return Promise.resolve(function step(v) { | ||
const res = g.next(v); | ||
if (res.done) return res.value; | ||
return res.value.then(step); | ||
}()); | ||
} | ||
return run(gen); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters