Skip to content

Instantly share code, notes, and snippets.

@mischah
Created April 14, 2019 20:59
Show Gist options
  • Select an option

  • Save mischah/dd05a2b2be4aabee0b05da37fb94d403 to your computer and use it in GitHub Desktop.

Select an option

Save mischah/dd05a2b2be4aabee0b05da37fb94d403 to your computer and use it in GitHub Desktop.

Revisions

  1. mischah created this gist Apr 14, 2019.
    14 changes: 14 additions & 0 deletions delay.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    // Promisified setTimeout
    const delay = (duration = 0) =>
    new Promise(resolve =>
    setTimeout(() => {
    resolve();
    }, duration)
    );

    // Usage
    async function myFunction() {
    console.log('Do something');
    await delay();
    console.log('Do something else');
    }