-
• #2
It's built-in to all the new firmwares: http://www.espruino.com/Reference#Promise
I guess you're using ESP8266 so I'm not sure if you're using a build that has it disabled or something, but on an official board with up to date firmware then it's just already there as soon as you type
new Promise(...)
-
• #3
I try use promise, but it's work strange:
const p = new Promise(function(resolve, reject) { setTimeout(resolve, 100); setTimeout(reject, 200); }); p.then(function() { console.log('resolved'); }).catch(function() { console.log('rejected'); });
output:
resolved
Uncaught Error: Unhandled promise rejection: undefinedBolded text printed, because reject called after resolve, but promise must be ignore change state at second call.
And what about async\await?
-
• #4
I try use promise, but it's work strange
This looks like a bug - I've filed one for the issue here: https://github.com/espruino/Espruino/issues/1433
Looks like we didn't test for that as all code I've seen to date just calls one of the other - not both.
And what about async\await?
No, they're not implemented on Espruino.
I saw an old thread referencing Promises, but can't seem to find an official Promise module anywhere. I tried an implementation by @favo from this thread but a simple
console.log()
test had erroneous results where callbacks occurred before resolutions.Trying to save a bit of time myself and hoping this was already implemented.