Closed kj800x closed 5 years ago
I just started digging into nodent-compiler
to see how hard this would be to PR... There's an undocumented option $Promise
which does exactly what we need!
https://github.com/MatAtBread/nodent-compiler/blob/03c49cf/compiler.js#L269
Problem Statement
We would love to use this plugin, but we cannot use native promises due to the fact that there isn't yet a standard cross-browser solution for reporting unhandled promise rejections. For this reason, our team is using
Q.Promise
instead of nativePromise
. We would like fast-async to use a configurable implementation ofPromise
, so that we can configure it to useQ.Promise
instead of native promises.We have attempted a solution similar to the "Promises polyfill" section of the README using
webpack.DefinePlugin
to rewritePromise
, but it does not support our case, as we cannot universally rewrite usages ofPromise
toQ.Promise
in the codebase. Some of our other plugins generate native promises which we do not want to change.Proposed Solution
There is a new configuration option, which when set causes
fast-async
to use it's value instead ofPromise
in generated code.Proposed Config
Sample Input
Sample Output
Note that the Promise inside of
sleep
should not useQ.Promise
, since it was explicitly written to use native Promise, but thePromise
s generated byfast-async
should useQ.Promise