-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BasePHP.#handleRequest(): Replace double "await await" with .then()
Before this PR, #handleRequest used the following construction: new Promise(async (resolve, reject) => { try { await await ccall(); resolve(); } catch(e) { reject(e); } }); The double await was in there due to a weird issue found earlier on, where the singular `await` still resolved to a promise. However, a promise with an async function and a double await, is a confusing beast. The Promise A+ specification claims that a promise never resolves to another promise. It always resolves to the final value: https://promisesaplus.com/ Every attempt to reproduce the original issue have failed. Perhaps it was a browser bug or gamma rays, who know? The important thing is: if ccall() returns a promise, it is now resolved to its final value. Therefore, this commit removes the async/await await construction, and replaces it with a simpler one relying on .then(). Importantly, ccall() may return either a promise (when Asyncify is involved, e.g. for network calls) or a primitive value. This commit takes special care to handle both use-cases, and provides tests to ensure that both synchronous and asynchronous exceptions are correctly handled. Authored by: @kozer Co-authored by: @zieladam
- Loading branch information
Showing
2 changed files
with
97 additions
and
20 deletions.
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