code: function setTimeoutContext(fn, ctx, timeout) {
    var id;
  
    var cancel = function() {
      clearTimeout(id);
    };
  
    id = setTimeout(function() {
      ctx.removeListener('cancel', cancel);
  
      fn();
    }, timeout);
  
    ctx.once('cancel', cancel);
  }
docs: Set timeout with cancel support