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 :: remove part of string javascript 
Javascript :: javascript loop x times 
Javascript :: javascript check if string contains special characters 
Javascript :: MongoDb user find 
Javascript :: javascript datetime format 
Javascript :: javascript get focusable elements 
Javascript :: gesture handling with react native expo 
Javascript :: how to add number in string in javascript 
Javascript :: how to get a user input in js 
Javascript :: remove selected js 
Javascript :: array shuffle 
Javascript :: field array using useFormik 
Javascript :: create a loop that runs through each item in an array 
Javascript :: getDataSnapshotFirebase 
Javascript :: jquery selector parent on hover 
Javascript :: how to send axios delete to the backend reactjs 
Javascript :: array javascript some vs every 
Javascript :: get specific parent element jquery 
Javascript :: get odd elements of list javascript 
Javascript :: js split string every n characters 
Javascript :: turnery opertaor js 
Javascript :: js fibonacci sequence 
Javascript :: display date in javascript 
Javascript :: return a date time object in yyyy-mm-dd hr:min:sec 
Javascript :: react prevent form submission on enter key press inside inputs 
Javascript :: elastic get data from specific fields 
Javascript :: java parse json 
Javascript :: looping through an array javascript sum 
Javascript :: socket.io cors 
Javascript :: express command not found mac 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =