Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
Comment

javascript polling

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

clearInterval(myPollingInterval); //stop the polling 
Comment

PREVIOUS NEXT
Code Example
Javascript :: find duplicates in array 
Javascript :: angular right click action 
Javascript :: move element onclick javascript 
Javascript :: difference between undefined and null javascript 
Javascript :: react js form radio input using hooks 
Javascript :: convert milliseconds to time javascript 
Javascript :: switch to window in testcafe 
Javascript :: next connect 
Javascript :: react js alert popup example 
Javascript :: extract from a string in javascript 
Javascript :: Javascript show password... 
Javascript :: moment to date object 
Javascript :: get date from datepicker 
Javascript :: local reload go to top 
Javascript :: convert exp date token to date 
Javascript :: email regex javascript 
Javascript :: TypeError: navigation.getParams is not a function. 
Javascript :: sequelize include twice 
Javascript :: jquery templates 
Javascript :: p5js left mouse click 
Javascript :: socket..io 
Javascript :: serve static files from express 
Javascript :: line separator with text in the center react native 
Javascript :: moment time from now 
Javascript :: js string to boolean 
Javascript :: sequelize select fields 
Javascript :: password regex javascript long way 
Javascript :: create express js project 
Javascript :: combine the values of 2 arrays in key = value jquery 
Javascript :: arrays inside array of objects 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =