4 ms·
This is why we need proper, rich stream abstractions in JS that integrate well with promises. Promises by themselves are not enough. Note that a real world imp
by spion 4y ago
This is why we need proper, rich stream abstractions in JS that integrate well with promises. Promises by themselves are not enough.
Note that a real world implementation of this would also limit the number of concurrent requests - another reason to have streams with rich concurrency options.
- spankalee 4y agoModern JavaScript has fine stream abstractions in WHATWG Stream and async iterables, and Dart has the same unhandled Future issue as JS. Dart generally has fewer, but nicer, libraries for dealing with collections of Futures, but JS has a lot of npm libraries and is somewhat catching up with additions like Promise.{any,allSettled,race} and Array.fromAsync().
- spion 4y agoAsync iterables are bare-bones, and WHATWG Streams are not much better. I removed Dart from the comparison.
- no_wizard 4y agoThis is what observables are all about, yet `rxjs` and the like never gained any wide spread traction, despite solving so many of these issues very well. Not to mention there are many great upsides to using observables as well! I remember at the time Promise was gaining acceptance toward a standard there was a rich debate about adding observables and leveraging this as the async primitive but developers complained loudly that they wanted something more primitive. Then everyone complained about Promise being too verbose, so we got async await and async iterables. And now that we have said primitive, people say well where are the promise helpers, promises alone aren't enough! All of this could have been avoided with observables
- spion 4y agoObservables didn't properly integrate with promises at the right time - if they did they'd be accepted way more easily (e.g. `.first()` returning a Promise rather than an observable or `using` accepting promise return values and/or async functions and returning promises as a result). I gave the Dart API originally as an example, as it has careful considerations for when to return Future<T> instead of another Stream<T> (https://api.dart.dev/stable/2.18.7/dart-async/Stream-class.html https://api.dart.dev/stable/2.18.7/dart-async/Stream-class.h...) - examples include first(), last(), asyncMap etc.