const caf = window.cancelAnimationFrame;
const raf = window.requestAnimationFrame;
export const cancelAnimationTimeout = frame => caf(frame.id);
export const requestAnimationTimeout = (callback, delay) => {
  const start = Date.now();

  function timeout() {
    if (Date.now() - start >= delay) {
      callback.call();
    } else {
      frame.id = raf(timeout);
    }
  }

  const frame = {
    id: raf(timeout)
  };
  return frame;
};