Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to poll efficiently in javascript

const poll = async function (fn, fnCondition, ms) {
  let result = await fn();
  while (fnCondition(result)) {
    await wait(ms);
    result = await fn();
  }
  return result;
};

const wait = function (ms = 1000) {
  return new Promise(resolve => {
    setTimeout(resolve, ms);
  });
};

let fetchReport = () => axios.get(reportUrl);
let validate = result => !result.data.summary;
let response = await poll(fetchReport, validate, 3000);
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to submit form on changed url in function in jquery 
Javascript :: how to add checked in javascript 
Javascript :: create new angular project with specific version 
Javascript :: javascript sum table row values 
Javascript :: promise.race 
Javascript :: return all elements of javascript array except the first item 
Javascript :: jquery display text in div 
Javascript :: javascript time 
Javascript :: addition of all elements of array in js 
Javascript :: Material-ui add comment icon 
Javascript :: log odd numbers js 
Javascript :: what is status 400 in react 
Javascript :: list of higher-order functions javascript 
Javascript :: how to get the inner width of a parent div for canvas 
Javascript :: is jwt token expired 
Javascript :: axios delete with data 
Javascript :: remove undefined element from array 
Javascript :: webpack-bundle-analyzer react 
Javascript :: regex youtube id 
Javascript :: remove duplicate value from array 
Javascript :: js base64 encoding 
Javascript :: write to file but dont overwrite fs.writeFile node 
Javascript :: http node 
Javascript :: how to check if the first letter of a string is capitalized or uppercase in js 
Javascript :: why does my form reload the page? html js 
Javascript :: async javascript 
Javascript :: typescript interface with unknown keys 
Javascript :: javascript split string by multiple characters 
Javascript :: round down the number javascript 
Javascript :: js find all max number indexes in array 
ADD CONTENT
Topic
Content
Source link
Name
2+6 =