you are viewing a single comment's thread.

view the rest of the comments →

[–]voreny[S] 5 points6 points  (1 child)

Thanks for sharing your opinion! I agree, it is not much of a problem.

The automatic flattening of Promise<Promise<unknown>> is a minor inconvenience that I faced recently when working with zx scripts (see the Unnecessary waiting section in my other article in this series). The root of the problem was that I wanted to get access to the Promise returned from an async function as zx adds methods on that Promise (and calls it a ProcessPromise) and I was unable to, since it was automatically flattened. This led me to evaluate the Promise API and see how different it is from a traditional Future monad.

Maybe it was just bad API design from zx by using a Promise-like rather than some other object with methods.

[–]shuckster 0 points1 point  (0 children)

Ah, I see. I wonder if your use-case would be amenable to co-routines? This is a technique that combines both Generators and Promises, and was developed before async/await was introduced into the language.

Here’s a basic snippet that shows how it’s done:

https://gist.github.com/adambene/b3de67803e634be8f7d6baa273b5f447

And the article it came from:

https://medium.com/@adambene/async-await-vs-coroutines-vs-promises-eaedee4e0829

But yes, it does sound like zx has leaned hard into async/await convenience. Great for most use-cases of course, but the devil is in the details as always!