I have a situation like this:
async function thirdPartyCode(a) {
if (a == ...) {
return myPromiser(...) // can allow and act on this
}
let b = await someoneElsesPromiserB(...)
if (b == ...) {
let c = await myPromiser(...) // must error on this
...
}
let d = await someoneElsesPromiserD(...)
let e = myPromiser(...) // note no await
return e // can allow and act on this
}
As the author of myPromiser() and caller of this thirdPartyCode(), I'd like to detect whether the myPromiser()'s promise is used as the returning promise of the async function. This is the only legal way to use it in this particular kind of async function's calling context. It cannot be awaited on, or have .then() clauses attached to it while it is inside this function.
If there were a way to know "When is the body of an async function actually finished", that would be a wedge to solving it.
(Note: The strange limitations in this question are a by-product of using the Emscripten Emterpreter. The limits may (?) need not apply when simulated pthreads are available via WebAssembly workers / SharedArrayBuffer / etc. But those bleeding-edge browser features aren't enabled by default at time of writing...so this unusual desire comes from wanting a compatible subset of code to be legal.)
from Detecting "returned promise only" status of an async function
No comments:
Post a Comment