const Common = {
  /**
   * 睡眠指定毫秒
   * @param {number} ms - 毫秒数，必须是非负数
   * @returns {Promise<void>}
   */
  async sleep(ms) {
    if (!Number.isFinite(ms)) {
      return Promise.resolve();
    }
    if (ms === 0) {
      return Promise.resolve();
    }
    return new Promise((resolve) => {
      const timer = setTimeout(resolve, ms);
      return () => clearTimeout(timer);
    });
  },
};

export default Common;
