Skip to content

solution: solved the 4th challenge of promises async await (4) - #6

Open
PushpakRaut wants to merge 3 commits into
The-Code-Dose:mainfrom
PushpakRaut:solution/promises/4_1
Open

solution: solved the 4th challenge of promises async await (4)#6
PushpakRaut wants to merge 3 commits into
The-Code-Dose:mainfrom
PushpakRaut:solution/promises/4_1

Conversation

@PushpakRaut

Copy link
Copy Markdown
Contributor

What does this PR do
This PR Solved the 4th challenge of promises-async-await

#Screenshot

image

#Changes

solution update.

@PushpakRaut

Copy link
Copy Markdown
Contributor Author

updated!!!

Comment thread solutions/promises_async_await/4.js Outdated
Comment on lines +1 to +15
const firstPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("1. Finished");
}, 1000);
});
const secondPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("2. Finished");
}, 2000);
});
const thirdPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve("3. Finished");
}, 3000);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create a single function that takes in the seconds as argument and returns a promise

@PushpakRaut

Copy link
Copy Markdown
Contributor Author

Updated as per suggestion...

return new Promise((resolve, reject) => {
setTimeout(() => {
resolve(message);
}, seconds);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be milliseconds not seconds

}, seconds);
});
}
Promise.all([promise("1. Finished", 1000), promise("2. Finished", 1000), promise("3. Finished", 1000)]).then((res) =>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Promise.all([promise("1. Finished", 1000), promise("2. Finished", 1000), promise("3. Finished", 1000)]).then((res) =>
Promise.all([promise("1. Finished", 1000), promise("2. Finished", 2000), promise("3. Finished", 3000)]).then((res) =>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants