-
• #2
This was actually mentioned on the Espruino wishlist and there's a more in-depth discussion here: https://github.com/espruino/Espruino/issues/1272
Unfortunately due to the way Espruino executes JavaScript it is particularly difficult to implement async/await. A very limited implementation (no support for FOR/WHILE/TRY..CATCH/SWITCH/etc) wouldn't be as bad, but I think it would end up being frustrating to use.
-
• #3
Ah, thanks! I'll remember to check the GitHub issues first in future ;)
-
• #4
I'll remember to check the GitHub issues first in future ;)
Honestly I'd prefer people asked on the forum rather than creating GitHub issues :)
Basically it's something I'd like to add - and which seems to be really popular - but at the moment it is very tricky to handle properly so I'd be surprised if it got done this year :(
-
• #5
Can you use babel?
Using a random googled input:
class Waiter { async wait() { return await Promise.resolve(1); } } new Waiter() .wait() .then(alert); // 1
-
• #6
@Wilberforce I noticed in the GitHub issue that Gordon linked to above that there are a few Babel examples. Yes, I think that will work just fine for now, thanks!
-
• #7
Sorry, I totally forgot to add transpiling as an option.
If you use the
espruino
NPM package it's got a handy command-line tool that you can use to upload code - so it's pretty easy to just shove that on the end of the command-line to a transpiler (or use the-w
option to watch a file for changes).I'm still a bit iffy about pulling the whole of Babel into the Web IDE, but if there are web services that can publicly be used I'm very happy to add an option to those to it?
Any chance that Espruino will supports ES6's async/await syntax in future?
I've found that it is easier to use and much more readable than using Promises with .then, or callbacks for that matter. It is very much suited to the asynchronous nature of connected devices, where you typically send a command and then wait for reply.