Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function sleep(duration) {
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- resolve();
- }, duration);
- });
- }
- // usage
- async function fn() {
- doStuff();
- // sleep for 1 second
- await sleep(1000);
- doAnotherStuff();
- }
- function doStuff() {
- console.log('foo');
- }
- function doAnotherStuff() {
- console.log('bar');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement