Last active
February 6, 2018 13:15
-
-
Save NitsanBaleli/f650d6a3504f7ac64e0b735ecc71bb51 to your computer and use it in GitHub Desktop.
Loop ajax requests with Rxjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = ["[email protected]", "[email protected]"]; | |
const emails = () => array; | |
module.exports = emails; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Rx = require('rxjs/Rx'); | |
const axios = require('axios'); | |
const emails = require('./emails'); | |
let array = emails(); | |
let baseUrl = "https://api-staging.antelopesystem.com/SignalsServer/users/forgotpassword?appId=1&email="; | |
//we use flatMap becuase order doesnt matter | |
//https://www.learnrxjs.io/operators/transformation/mergemap.html | |
var source = Rx.Observable.from(array).flatMap((email) => { | |
return Rx.Observable.fromPromise(axios.get(`${baseUrl}${email}`).then((res) => { | |
console.log(`completed with ${email}`); | |
return res; | |
})).delay(30) | |
}); | |
var subscription = source.subscribe( | |
(x) => {}, | |
(err) => {}, | |
() => console.log('Completed')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment