6 ms·
> no async/await Doesn't this mean we're basically back to callback hell? This was one of the primary criticisms of Node before async/await was introduced.
by Asraelite 5y ago
> no async/await
Doesn't this mean we're basically back to callback hell? This was one of the primary criticisms of Node before async/await was introduced.
- skywal_l 5y agoCallback hell was before the introduction of Promises. Promises tried to abstract away the callback mechanism and it made things a little clearer, but you still had the pyramid effect of successive Promises. Await/Async kind of streamlined all this.
- dsnr 5y agoI still somewhat prefer the readability of promises vs. await. I like the expressiveness of a then/catch as functions as opposed to try/catch blocks, which I‘ve always disliked. But I agree that await is more suitable for more complex scenarios.
- nsonha 5y agoasync/await is just a syntax sugar, most languages didn't have it until very recently when it became a trend or something. In OCAML it's just like any other monad you use the bind operator instead. No need for special keywords.
- lolive 5y agoI will probably be banned from any Haskell forum after that, but isn't the do notation a async, and the <- a await ?
- nsonha 5y agowhat do you mean by banned? You got it the other way around, async is a special case of the do notation, and await is the special case of <-
- Zababa 5y agoIt's basically that. Example: hello.then(a => return op1(a)).then(b => return op2(b)).then(c => console.log(c); const a = await hello(); const b = await op1(a); const c = await op2(b); console.log(c) In Haskell (>>= is pronounced "bind", \a -> is like a => in JS): hello >>= (\a -> op1 a >>= (\b -> op2 b >>= (\c -> show c))) do { a <- hello; b <- op1 a; c <- op2 b; show c } There is a slight difference, in that JS promises aren't monads. But the idea is still here.
- rsrsrs86 5y agodo { a <- m; return r } Ia desugared to m >>= (\a -> return r) Think of it m.then(function (a) return r)
- dmitriid 5y ago> it's just like any other monad Ah yes. The magic word "just". You "just" do something that does something. And yet even the example in the article uses Promise.then and eventual callback hell.
- nsonha 5y agoI have to admit I don't know much about ReScript and only have very basic exposure to OCAML, here is how you do await in it: https://github.com/ocsigen/lwt https://github.com/ocsigen/lwt The `let* in` is a generic syntax for monads, it doesn't need a special one just for promise. This was in fact a debate back when async/await was in consideration for ECMAScript, but special syntax is hip so now we have `async/await` for Promise, `.?` for optionals and `flatMap` for arrays, basically the same thing.
- ackfoobar 5y agoHaving seen too much `.map(_.map(` in Scala, I'd argue that different words/syntax for different things (that happen to have the same algebraic structure) is a good thing.
- nsonha 5y agoyes but they don't have to be keywords or magical syntax, can be defined in user land
- dmitriid 5y ago> here is how you do await in it That's how you do "await" in a third-party library that brings with it a lot of other baggage. And I doubt it works in ReScript. > The `let* in` is a generic syntax for monads Ah yes. "Just" putting `let*` there magically makes promises work, is that what you're saying? It turns out Lwt gained support for let* sytax only in April 2020. Stupid them. They didn't know they just had to use it.
- ackfoobar 5y ago
- kevingadd 5y agoC# 5.0 introduced async/await in mid-2013 (late 2012 depending on how you count it), and F# had it before that in its version 2.0 (~2007). It's a pretty old "trend".
- nsonha 5y agoanything else other than those 2? An idea that .Net started, could be good could be bad, but the .Net association isn't added credibility. async/await aren't keywords in F# and kotlin
- afavour 5y ago> anything other than those two? Rust?
- nsonha 5y agoI was arguing that languages are following the "add async/await" trend recently, including rust. That other comment brought up that it exists in C# for a long time, hence not a recent trend.
- dharmaturtle 5y agohttps://en.wikipedia.org/wiki/Async/await#History https://en.wikipedia.org/wiki/Async/await#History F# in 2007 C# in 2012 Python in 2015 Typescript in 2015 Javascript in 2017 Rust in 2019 C++ in 2020 Swift in 2021
- sideeffffect 5y agoI'm almost sure that Haskell has had its "do notation" even before 2007. And maybe even Scala its "for comprehension".
- dharmaturtle 5y agoYeah - I was limiting my post to explicit async/await. Don Syme, creator of F#, had a nice thread on the roots of async/await, though it doesn't mention do-notation: https://mobile.twitter.com/dsymetweets/status/1407400817917939713 https://mobile.twitter.com/dsymetweets/status/14074008179179... I'm still annoyed that most other languages stole async/await... but not the more general monadic/do notation. Instead we get elvis operators, chaining functions, etc.