tiny-when

JS library that periodically checks _when_ a condition is satisfied.

Usage no npm install needed!

<script type="module">
  import tinyWhen from 'https://cdn.skypack.dev/tiny-when';
</script>

README

Behance Tiny-When Build Status NPM version

This Browser / Node.js library that periodically checks when a condition is satisfied.

Features

  • Pass a condition to check the interval
  • Set the options for interval of checks and the max number of checks
  • Returns a promise that is resolved or rejected based on the options

Usage

const when = require('tiny-when');

function condition() {
  return window.adobeAnalytics && window.liveFyre;
}

const options = {
  maxChecks: 30,
  intervalInMs: 100
}

when(codition, options)
.then(function() {
  console.log('Adobe Analaytics and LiveFyre loaded and are ready!');
});

When Arguments:

  • condition - a function that checks to see if a condition is met (e.g., function() { return window._satellite && window.s_adbadobenonacdc }).
  • options.intervalInMs - defaults to 300 - Number of MS before checking the condition
  • options.maxChecks - defaults to 30 - Number of Max checks

License

Apache-2.0