src/delay.js
async function clear(promise) {
    if (!pendingPromises.has(promise)) {
      return Promise.reject(new YError('E_BAD_DELAY'));
    }
    const { timeoutId, reject } = pendingPromises.get(promise);

    clearTimeout(timeoutId);
    reject(new YError('E_DELAY_CLEARED'));
    pendingPromises.delete(promise);
    log('debug', 'Cleared a delay');
  }
async function clear(promise) {
    if (!pendingPromises.has(promise)) {
      return Promise.reject(new YError('E_BAD_DELAY'));
    }
    const { timeoutId, reject } = pendingPromises.get(promise);

    clearTimeout(timeoutId);
    reject(new YError('E_DELAY_CLEARED'));
    pendingPromises.delete(promise);
    log('debug', 'Cleared a delay');
  }
async function clear ( promise ) { if ( ! pendingPromises . has ( promise ) ) { return Promise . reject ( new YError ( 'E_BAD_DELAY' ) ) ; } const { timeoutId , reject } = pendingPromises . get ( promise ) ; clearTimeout ( timeoutId ) ; reject ( new YError ( 'E_DELAY_CLEARED' ) ) ; pendingPromises . delete ( promise ) ; log ( 'debug' , 'Cleared a delay' ) ; }
Cancel an earlier created delay
@param  {Promise}   promise
The promise of the delay to cancel
@return {Promise}
A promise resolved when cancellation is done.
@example
try {
const delayPromise = delay.create(1000);
await Promise.all(delayPromise, delay.clear(delayPromise));
console.log('1000 ms elapsed!');
} catch (err) {
if(err.code != 'E_DELAY_CLEARED') {
trow err;
}
console.log('Cancelled!'));
}
// Prints: Cancelled!
Cancel an earlier created delay