You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While trying to implement Promise.finally I have tried to understand the implementation of promises in espruino, and it does not appear to work correctly. The chaining of promises can't work right, since promises form a DAG, not a chain. I think the promise implementation could be simplified and made to work correctly if the chain code isn't used.
Here is an example that fails in today:
functiondelay(ms){returnnewPromise(r=>setTimeout(r,ms));}varp=delay(1000);p.then(()=>'a').then(x=>console.log(x));//logs a after a secondp.then(()=>'b').then(x=>console.log(x));//should log b after a second, but logs a instead
This is probably because jswrap_promise_then calls on jswrap_promise_get_chained_promise which checks if the promise has been chained already and uses the chained promise if it has. Therefore the two thens return the same promise, which they obviously shouldn't:
While trying to implement
Promise.finally
I have tried to understand the implementation of promises in espruino, and it does not appear to work correctly. The chaining of promises can't work right, since promises form a DAG, not a chain. I think the promise implementation could be simplified and made to work correctly if thechain
code isn't used.Here is an example that fails in today:
This is probably because jswrap_promise_then calls on jswrap_promise_get_chained_promise which checks if the promise has been chained already and uses the chained promise if it has. Therefore the two
then
s return the same promise, which they obviously shouldn't:They should both return a new unresolved promise
The text was updated successfully, but these errors were encountered: