Skip to content
This repository has been archived by the owner on May 28, 2024. It is now read-only.

More use cases #8

Open
iongion opened this issue Jul 10, 2020 · 1 comment
Open

More use cases #8

iongion opened this issue Jul 10, 2020 · 1 comment

Comments

@iongion
Copy link

iongion commented Jul 10, 2020

Love this project, you can try to make it cover / exemplify a real world case.

A fictive security camera system where you are "Fetching multiple images from N cameras at T-interval".

A sample:

const jitterTime = require('jitter-time');

const images = ['1.jpeg', '2.jpeg', '3.jpeg'];
const imageElements = images.map((url) => {
  const image = document.createElement('img');
  image.setAttribute('src', url);
  return image;
});

function syncDataWithServer() {
  const { url, index } = this;
  const noCacheKey = encodeURIComponent(Math.random());
  const freshUrl = `${url}?v=${noCacheKey}`;
  imageElements[index].setAttribute('src', freshUrl);
};

const queries = images.map((url, index) => {
  const POLL_INTERVAL = jitterTime(5, 0.2);
  return setInterval(syncDataWithServer.bind({ url, index }), POLL_INTERVAL);
});

// Cleanup
// queries.forEach((id) => clearInterval(id));
@iongion
Copy link
Author

iongion commented Jul 10, 2020

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant