Last active
March 26, 2023 18:27
-
-
Save Yenniferh/c0c8ffe38859f4b6cff3638fa7f68ff2 to your computer and use it in GitHub Desktop.
Avoid the callback hell by using promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { doTask1, doTask2, doTask3 } from './tasks'; | |
export function runCode() { | |
return Promise.all([doTask1(), doTask2(), doTask3()]) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const doTask1 = () => new Promise((resolve) => | |
window.setTimeout(() => resolve('Task 1') | |
, 300)); | |
export const doTask2 = () => new Promise((resolve) => | |
window.setTimeout(() => resolve('Task 2') | |
, 300)); | |
export const doTask3 = () => new Promise((resolve) => | |
window.setTimeout(() => resolve('Task 3') | |
, 300)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment