News for hackers. Stuff that matters.
Re:When to Use TypeScript – A Detailed Guide Through Common ... by ajxs on Sunday April 07, 2019 @09:50PM (#19601294)
I actually just made the term up myself just then to describe my feelings about the fact that all of the methods in our service layer are just `await this(); await that(); await another(); //...` and so on. Please be aware that this post is describing my own experiences in back-end web-app development using Node. I feel I'm courting more controversy here, but if you're using `async/await` ad-nauseum your app might not actually be as async as you think it is. Of course this is a godsend compared to the callback hell that it replaced, but I can't help feeling that this is the right solution to the wrong problem. In my experience, most of the server-side applications I've seen written in Node are only practically asynchronous at the router level. Once you get into the controllers they tend to become entirely procedural and effectively completely synchronous. With the exception of the rare `Promise.all(...).then(...)`.... If you're using `await` on every single function call, it stops being syntactic sugar and just becomes more syntactic salt.
Re:When to Use TypeScript – A Detailed Guide Through Common ... by hn_throwaway_99 on Sunday April 07, 2019 @10:32PM (#19601496)
I completely disagree. Or rather I'd say if you're making a bunch of remote calls, and you need the results before taking the next step, then you're going to need to be doing something like this in any case. FWIW I feel a backend controller in Node is much easier to write, and to understand, with async/await than the equivalent patterns in Java.

As you put it, "Once you get into the controllers they tend to become entirely procedural and effectively completely synchronous" but that's because for most people it's far easier to think about a problem as a series of individual steps. Even then, if you have a bunch of serial awaits it's usually pretty trivial to go back and then await on a Promise.all() if you realize things can be run concurrently.

Re:When to Use TypeScript – A Detailed Guide Through Common ... by h1d on Monday April 08, 2019 @06:24AM (#19603826)
> easier to think about a problem as a series of individual steps

You sound like we can be innovative on how we code but how can steps that do

- Parse inputs

- Query database

- Return output

be asynchronous?

Unless I'm writing a background job that is decoupled from HTTP requests, everything after the router is synchronous.

Re:When to Use TypeScript – A Detailed Guide Through Common ... by ajxs on Sunday April 07, 2019 @10:51PM (#19601556)
I think I might not have explained myself too well up there. I was referring to entirely sequential async calls. Like: ``` Thing thing = await loadThing(); Thing other = await thing.doSomething(); thing = await saveThing(); // repeat x1000... ```

I see this over and over.

Re:When to Use TypeScript – A Detailed Guide Through Common ... by mschuetz on Monday April 08, 2019 @03:12AM (#19602867)
And what exactly is the problem with that?

"Thing thing = await loadThing(); ": Start loading thing, then await so the main thread can continue doing other stuff while thing is loaded.

"Thing other = await thing.doSomething();": Invoke some other function that does some stuff in the background, then await so the main thread can continue doing other stuff while thing does something.

"thing = await saveThing();": Saving can often be done in parallel so no need to block the App while something is saved. Invoke the save function, then await so the main thread can continue doing other stuff while thing is saved.

This gets you the advantages of async programming while still maintaining a legible coding style that looks similar to common synchronous code.

Re:When to Use TypeScript – A Detailed Guide Through Common ... by je42 on Sunday April 07, 2019 @11:20PM (#19601692)
we have await this() and await that() also in python aiohttp and we will have in C++ co_wait this() and co_wait that() and we have in C# await this() and await that() this is not something specific to JS / Typescript...
Re:When to Use TypeScript – A Detailed Guide Through Common ... by JamesBarney on Monday April 08, 2019 @12:57AM (#19602254)
I never mind writing out the awaits. But that might be because I remember what writing asynchronous code was like 10 year ago and damn await is nicer.
Re:When to Use TypeScript – A Detailed Guide Through Common ... by h1d on Monday April 08, 2019 @06:19AM (#19603806)
I agree. Everything should be synchronous unless stated otherwise. The amount of 'await' and 'async' appearing is almost on every few lines but that is Node.js' problem, not TS'.
Re:When to Use TypeScript – A Detailed Guide Through Common ... by sieabahlpark on Sunday April 07, 2019 @10:09PM (#19601392)
I think most people think async/await gives them all the previous benefits of async but doesn't
Re:When to Use TypeScript – A Detailed Guide Through Common ... by orange8 on Sunday April 07, 2019 @11:58PM (#19601919)
All the previous benefits of async? Did you mean promises, callbacks or async? async/await is just syntax sugar over promises.
Re:When to Use TypeScript – A Detailed Guide Through Common ... by mschuetz on Monday April 08, 2019 @03:14AM (#19602880)
What benefits don't we get with async/await?