Trying to come up with API, mixing in promise functionality like:
class Awaitable {
constructor () {
this.promise = Promise.resolve()
}
then (fn) {
// awaited result must be _this_ instance
return this.promise.then(() => fn(this))
}
}
let smth = await (new Awaitable())
console.log(smth)
This code creates recursion.
The main point is to have smth
to be the newly created thenable instance.
Stubbing then
with null
makes awaited result incomplete.
I wonder if that's possible at all, seems like there's some conceptual hurdle, I can't wrap my head around.