concatMap with deferreds / chaining promises
See original GitHub issueAny ideas on how I would do the equivalent of this in most?
http://jsbin.com/kodoni/2/edit?js,console
var source = Rx.Observable.of(1,2,3,4)
.concatMap(function(x) {
return Rx.Observable.defer(function() {
return new Promise(function(resolve, reject) {
setTimeout(function() {
resolve(x);
}, 1000);
});
});
})
.subscribe(function(i) {
console.log(i);
});
Issue Analytics
- State:
- Created 9 years ago
- Comments:14 (12 by maintainers)
Top Results From Across the Web
rxjs - Is Observable from chained promises equivalent of ...
It's just how I've been doing things and I like it. What you do need to do is use a switchMap or concatMap...
Read more >Resolve promises in sequence with RXJS (ConcatMap)
This article will be a short one mainly on resolving / handling promises in sequence using RXJS. One such example would be fetching...
Read more >Using and chaining promises in AngularJS - AirPair
A guide to using promises in AngularJS to create multi-layered ... can be deferred further until a 3rd promise has been resolved/rejected, in...
Read more >[Solved]-Is Observable from chained promises equivalent of ...
Coding example for the question Is Observable from chained promises equivalent of observables created with from and chained with concatMap?-rx.js.
Read more >Async and Await | Hacker News
Most deferred objects like Futures in Java and Promises in other ... Introduce back-pressure in the protocol, and concatMap becomes safer ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yay! 👍
Hey all, I had a similar but slightly different issue that this ticket helped me through- rather than trying to run fetch() multiple times on a list of urls, I was getting a stream of domainNames, and had a function that returned a promise with a list of records in the name. Finding out a way to flatten the results of that promise was a bit of a challenge for me- naively doing
concatMap(n => lookupRecords(n))
returned the whole array as an element, but I wanted to flatten the resulting records out into the stream.I used @briancavalier’s suggestion of unfolding to get by this, in slightly different form. It took me a pass or three to make right/not-ugly, so I built a library for the final version- most-promise-spread.
From the example there, I got
mostPromiseSpread(Promise.resolve([1,2,3,4]).forEach(x => console.log(x*2))
. For domainNames/records, it looks something like:domainNames.concatMap(n => mostPromiseSpread(lookupRecords(n))
.