Skip to content

Instantly share code, notes, and snippets.

@Yenniferh
Last active March 26, 2023 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Yenniferh/c0c8ffe38859f4b6cff3638fa7f68ff2 to your computer and use it in GitHub Desktop.
Save Yenniferh/c0c8ffe38859f4b6cff3638fa7f68ff2 to your computer and use it in GitHub Desktop.
Avoid the callback hell by using promises
import { doTask1, doTask2, doTask3 } from './tasks';
export function runCode() {
return Promise.all([doTask1(), doTask2(), doTask3()])
}
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