Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js poll dom

function pollDOM () {
  const el = document.querySelector('my-element');

  if (el.length) {
    // Do something with el
  } else {
    setTimeout(pollDOM, 300); // try again in 300 milliseconds
  }
}

pollDOM();
Comment

poll 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 :: getvalue data from datetimepicker 
Javascript :: how to check if a string is in a string js 
Javascript :: only allow numbers in text input in js 
Javascript :: js check window active 
Javascript :: tolowercase 
Javascript :: javascript from method 
Javascript :: encodeuri hashtag 
Javascript :: js transitions 
Javascript :: this is a problem related to network connectivity npm 
Javascript :: javascript random number in range 
Javascript :: react onclick div 
Javascript :: org.json.JSONException: End of input at character 0 of 
Javascript :: push-method-in-react-hooks-usestate 
Javascript :: could not resolve module fs react native 
Javascript :: js array find string element with max length 
Javascript :: nuxt lang 
Javascript :: node redis json set key 
Javascript :: history.push 
Javascript :: react multiple event handlers] 
Javascript :: text align in javascript 
Javascript :: javascript line through 
Javascript :: run nextjs in separate port 
Javascript :: json.stringify parameters 
Javascript :: startswith 
Javascript :: react-select default menu open 
Javascript :: react navigation navigator types 
Javascript :: discord bot playing game 
Javascript :: react native create shadows 
Javascript :: string to html 
Javascript :: how to convert milliseconds to time in javascript 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =