default.js 388 B

1234567891011121314
  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. }