: IdleDeadline) => any} callback
 * @param {object} options
 */
export function requestIdleCallback(callback, options) {
  if (typeof callback !== "function") {
    throw new Error("callback is not a function in requestIdleCallback");
  }
  let id = gNextId++;

  ChromeUtils.idleDispatch(deadline => {
    if (gIdleTable.has(id)) {
      gIdleTable.delete(id);
      callback(deadline);
    }
  }, options);
  gIdleTable.set(id, callback);
  return id;
}

/**
 * Cancels the given idle callback
 *
 * @param {number} id
 */
export function cancelIdleCallback(id) {
  if (gIdleTable.has(id)) {
    gIdleTable.delete(id);
  }
}
PK