6 ms·
Am I the only one who is happy using normal callbacks? I think they are the best representation of the asynchronous flow.
by Kiro 10y ago
Am I the only one who is happy using normal callbacks? I think they are the best representation of the asynchronous flow.
- kolme 10y agoWell, I was happy using normal callbacks, but then promises made me a bit happier and now I even happier with async/await. You can definitely write clean code with only callbacks, but one has to be pretty careful if there are many nested asynchronous actions. Promises and await make that code very much clearer.
- joshuahutt 10y agoAlso, if you're trying to do something after multiple async operations, you've got to manually count your callbacks. (As opposed to using Promise.all)
- elmigranto 10y agoNo. You use flow management library. Just how you don't manually execute multiple promises with `Array.forEach` and same manual counting. Latter just happens to be in stdlib while former is userland.
- euroclydon 10y agoPlease give an example of a flow mgmt lib.
- elmigranto 10y agoProbably the most popular one is `async` — http://caolan.github.io/async/ http://caolan.github.io/async/.
- tkxxx7 10y agoI really enjoy this one - https://github.com/bigeasy/cadence https://github.com/bigeasy/cadence
- shados 10y agoAnd then as you use promise based code more and more (including with async/await), you eventually come to realize that while it looked good at first, its deeply, deeply flawed, and is at best a stepping stone to Observables :)
- egeozcan 10y agoAn observable is semantically very different to a promise, even if it can be thought as a promise with subsequent success calls. Here is the proposal: https://github.com/tc39/proposal-observable https://github.com/tc39/proposal-observable
- shados 10y agoYour point being? The semantic is different, but everything a promise can do, an observable can do (with roughly the same amount of code), but the other way around isn't true. Observables are just better in basically every ways. Real world implementations also have proper error handling and decent APIs to handle aborting -today-, while the TC39 is still jumping back and forth trying to figure out how to handle it in promises so that Fetch can stop being useless.
- untog 10y agoI don't mind callbacks for async flow, but they involve a huge amount of boilerplate when it comes to error handling. Promises make that a lot better. I haven't yet switched over to await because of things like the issues described in this post - I don't mind async operations being a little clunky because it highlights where they're actually happening. Only using a simple keyword makes me worry that the flow control won't get as much attention. For me, Promises are a happy medium that allow you do to do simultaneous operations (mapping, Promise.all) a lot more easily than you can with callbacks, but more obtrusively than with await.
- deleted 10y ago[deleted]
- elmigranto 10y agoNo you're not. I'm fine with w/ever abstraction, but prefer callbacks and their composition (`async`, events, streams…) over others for simplicity and their behavior matching expectations.
- dclowd9901 10y agoI think "async functions" are peak async handling. That is either a function returns synchronously, or returns a promise. Anything more feels like fiddling.
- _Marak_ 10y agoI'm only using normal callbacks and async javascript iterators . No promises or await. Easier mental model, no surprises, still easy to organize.
- hitgeek 10y agoI'm also happy with normal callbacks, and have no plans on adopting promises or async/await. the flow control library "async" provides all the tools to keep code readable.