I’m “coding along” with The Coding Train 7.11: TensorFlow.js but when I want to use async/await in the editor I get an error. Is it not possible to use async in that editor or is there something I have to add for making it work?
You’re allowed to write code with async/await (your browser should definitively support it), and it works as it should (as promised). But I believe it’s just the editor here that displays the async/await syntax as an error (even though it’s valid syntax)! I think it comes down to p5js only supporting a certain version of ecmascript? (citation needed!), and since async / await is pretty new (somewhere between es2016 and es2017? I’m not sure exactly when! ) then it hasn’t been added to p5js’ syntax highlighting / static code error checker.
Since we’re running code in the browser / clientside, it should really just be a matter of browser support & async/await has been supported by all major browsers for a while!
digging into the code for the p5js web editor Seems it uses jshint for doing its static code analysis, and currently there’s an issue already open for supporting async/await here! , so I gave that issue a thumbs up at least! https://github.com/jshint/jshint/issues/2604
also just to note this down somewhere (not really important to this issue / thread I guess), it seems that it uses codemirror https://codemirror.net/, and there seems to be a lot of unused potential there (stuff I would want enabled!) in the addons section for it https://codemirror.net/doc/manual.html#addons. eg. the match-highlighter.js! (highlighting the selected variable other places in code), and also tern/tern.js for multiple occurrence matching & refactoring. But I guess at some point it would just make more sense to switch to your IDE of choice, where you have all the features you find comfortable!
When I watch your code it looks all right but if I rewrite the word ascync on line 13 it looks as in the uploaded picture.
yeah, it should only be a false positive error :), the code still runs if you press play right? (so don’t worry about the async / await errors, the best I think we can do for now is to ignore them in the web editor until it’s fixed )