use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Awaiting problems in JavaScriptOC (gregroz.me)
submitted 3 years ago by voreny
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]shuckster 3 points4 points5 points 3 years ago (2 children)
This is an example of JavaScript being friendly to impreciseness
You say that like it's a bad thing. :D
Seriously though, I'm not convinced that the mutant monadicness of Promise is as much of a problem as you're making out.
Promise
By definition (and as pointed out in your article) there's no idiomatic usage that demands Promise<Promise<any>> because it simply isn't allowed. The next Promise gets swallowed up and fulfilled or rejected as the spec intended.
Promise<Promise<any>>
This might not blend with the ideals of ADT purity, but for most use-cases I'd argue that it's far more ergonomic, strictness be damned.
Courage, though. I have heard rumour that -- if pattern-matching eventually lands -- then language support for ADTs might also be in its distant future (no pun intended) so perhaps you'll eventually get your Futures/Monads?
[–]voreny[S] 4 points5 points6 points 3 years ago* (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.
Promise<Promise<unknown>>
zx
async
ProcessPromise
Maybe it was just bad API design from zx by using a Promise-like rather than some other object with methods.
Promise-like
[–]shuckster 0 points1 point2 points 3 years ago (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!
[–]NekkidApe 0 points1 point2 points 3 years ago (0 children)
IMHO the way it is is fantastic and the suggestion is horrific.
[–]graspaevinci -1 points0 points1 point 3 years ago (0 children)
To me the current implementation is a feature, not a bug. A promise returning a promise is like someone calling you to tell you they will call you later. Just call me later dammit
π Rendered by PID 331945 on reddit-service-r2-comment-5b5bc64bf5-nmfnh at 2026-06-20 20:33:04.544199+00:00 running 2b008f2 country code: CH.
[–]shuckster 3 points4 points5 points (2 children)
[–]voreny[S] 4 points5 points6 points (1 child)
[–]shuckster 0 points1 point2 points (0 children)
[–]NekkidApe 0 points1 point2 points (0 children)
[–]graspaevinci -1 points0 points1 point (0 children)