Re:Mistakes to Avoid If You Work with Scala Futures
by BalinKing on Sunday February 21, 2021 @12:28AM
(#26211062)
I liked the writeup! In my experience, JavaScript Promise (mis)use can share some of these mistakes too—they're probably inherent to the synchronous->asynchronous learning process.
[ Parent
| on HN ]
Re:Mistakes to Avoid If You Work with Scala Futures
by jkells on Sunday February 21, 2021 @03:15AM
(#26211779)
For other JS developers the stuff about await isn't relevant. It's not the same as a JS async/await
In JS an await is just syntactic sugar around a then() on a promise. The Await in the article is a method to block the thread until a promise resolves, there is no equivalent in JS.
.NET has a similar mechanism with Task.Result with similar pitfalls
Re:Mistakes to Avoid If You Work with Scala Futures
by vigneshwaran on Sunday February 21, 2021 @10:32PM
(#26220567)
Yes. The async/await in JS is totally different from Await in plain Scala (without any frameworks)
Re:Mistakes to Avoid If You Work with Scala Futures
by goblin89 on Sunday February 21, 2021 @01:11AM
(#26211245)
What would be the equivalent to “sending tasks” to a Future instead of awaiting result (re mistake 1) but in JS with Promises? Is it about operating on unresolved promises and awaiting final values as late as possible? Or does that part not apply to JS?
Re:Mistakes to Avoid If You Work with Scala Futures
by danidiaz on Sunday February 21, 2021 @02:52AM
(#26211699)
The error is explicitly awaiting for the result; "sending tasks" to the future is the correct way, and corresponds to "then" in Promise.
Re:Mistakes to Avoid If You Work with Scala Futures
by vigneshwaran on Sunday February 21, 2021 @12:16PM
(#26215216)
Thank you for your comment. Yes I felt that the problems could be present in other languages as well but I don't know any other.