Answers for "javascript polling"

0

polling in js

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);
Posted by: Guest on September-07-2021
0

javascript polling

var myPollingInterval = setInterval(function(){
  //make ajax request here                                         
}, 2000);

clearInterval(myPollingInterval); //stop the polling
Posted by: Guest on October-28-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language