RxJs v6 का उपयोग करके मई 2019 को अपडेट करें
अन्य उत्तर उपयोगी पाए गए, और zipउपयोग के बारे में अरनौद द्वारा दिए गए उत्तर के लिए एक उदाहरण प्रस्तुत करना चाहते थे ।
यहाँ एक स्निपेट है जो Promise.allआरएक्सजे के बीच और समतुल्यता को दर्शाता है zip(नोट भी, rxjs6 में कि ज़िप अब "rxjs" का उपयोग करके कैसे आयात किया जाता है और ऑपरेटर के रूप में नहीं)।
import { zip } from "rxjs";
const the_weather = new Promise(resolve => {
setTimeout(() => {
resolve({ temp: 29, conditions: "Sunny with Clouds" });
}, 2000);
});
const the_tweets = new Promise(resolve => {
setTimeout(() => {
resolve(["I like cake", "BBQ is good too!"]);
}, 500);
});
let source$ = zip(the_weather, the_tweets);
source$.subscribe(([weatherInfo, tweetInfo]) =>
console.log(weatherInfo, tweetInfo)
);
Promise.all([the_weather, the_tweets]).then(responses => {
const [weatherInfo, tweetInfo] = responses;
console.log(weatherInfo, tweetInfo);
});
दोनों से आउटपुट समान हैं। ऊपर चल रहा है देता है:
{ temp: 29, conditions: 'Sunny with Clouds' } [ 'I like cake', 'BBQ is good too!' ]
{ temp: 29, conditions: 'Sunny with Clouds' } [ 'I like cake', 'BBQ is good too!' ]