File: src/utils/setCancellableInterval.js

Recommend this page to a friend!
  Classes of Jeremy Judeaux   Cancellable chain of promises   src/utils/setCancellableInterval.js   Download  
File: src/utils/setCancellableInterval.js
Role: Auxiliary script
Content type: text/plain
Description: Auxiliary script
Class: Cancellable chain of promises
Run chains of actions based on asynchronous events
Author: By
Last change: Update of src/utils/setCancellableInterval.js
Date: 2 years ago
Size: 584 bytes
 

Contents

Class file image Download
const setCancellableInterval = (callback, delayParam = +Infinity, tokenParam = undefined) => { let delay = delayParam; let token = tokenParam; if (arguments.length === 2 && typeof delayParam === 'object') { token = delayParam; delay = 0; } if (!token) { return setInterval(callback, delay); } if (token.cancellationRequested) { return undefined; } const id = setInterval(function onTimeout(...args) { callback.apply(this, args); }, delayParam); token.register(() => clearInterval(id)); return id; }; export default setCancellableInterval;