javascript - JS artificial delay between async requests -
i trying find way introduce delay between requests. have async method called likephotos iterates array of photos , calls likephoto() each. rather fire off @ same time have second delay between each call likephoto , return caller once complete.
async likephotos(photos) { // run function on photos var likes = photos.map(function(p, index, photos){ this.likephoto(p); }, this); return promise.all(likes); } likephoto(p) { let { token } = this.state; return new promise(function(resolve, reject) { http .post('/api/photos/' + p.id + '/likes', {}, { authorization: 'bearer ' + token }) .then((response) => { console.log("yeah"); resolve(); }) .catch((error) => { console.log("failed photo: " + p.id); reject(error.message); }) }); }
settimeout doesn't quite seem fit bill here. i'm js noob suggestions appreciated!
add counter simultaneous http requests. browsers can send 6 simultaneous requests. after sending 6 requests wait response 6 requests. once response 6 requests received, send 6 requests.
Comments
Post a Comment