市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
388 B

  1. export async function delay({seconds, milliseconds} = {}) {
  2. let duration;
  3. if (typeof seconds === 'number') {
  4. duration = seconds * 1000;
  5. } else if (typeof milliseconds === 'number') {
  6. duration = milliseconds;
  7. } else {
  8. throw new TypeError('Expected an object with either `seconds` or `milliseconds`.');
  9. }
  10. return new Promise(resolve => {
  11. setTimeout(resolve, duration);
  12. });
  13. }