Skip to content

Instantly share code, notes, and snippets.

@muslemomar
Created October 25, 2022 12:00
Show Gist options
  • Save muslemomar/1ea8d8e908e940e15d63f9507a3c21df to your computer and use it in GitHub Desktop.
Save muslemomar/1ea8d8e908e940e15d63f9507a3c21df to your computer and use it in GitHub Desktop.

Promise Discussion Questions

  1. In your own words, what does asynchronous mean?
  2. In your own words, what is a promise?
  3. In your own words, why is it called a Promise?
  4. In your own words, why is it called await?
  5. Please read the common mistakes section of MDN here and summarize what the common mistakes are.
  6. Why would you use async/await over .then?
@daryanaji
Copy link

Room 8, Noor Ridha, Zoriana, Riham, Muhammad Raslan, Darya

  1. Asynchronous is a technique that enables us to start a task that might take time. So we are capable of moving on to other tasks without having to wait for it to finish and when it is done, the program receives its result.

  2. A promise is an object hat shows if asynchronous operation was completed or failed.

  3. Cause when the result is a value the promise will be fulfilled otherwise it's even rejected or pending.

  4. It's called await becuase it makes the function waits for the promise.

  5. -The first mistake happens when we create a new promise but we forget to return it.
    -Unecessary nesting.
    -Not terminating the chains with catch.

  6. Async/Await is used to reduce the amount of syntax required to use promise-based APIs, When promises and generators are combined, async/await behaves similarly. Promises are always returned by async functions.

@shadmustafa
Copy link

shad mustafa- baraa nazar- nisreen hamzah- hevar tofiq- muhamad othman- maryam salah

1-doing multi tasking without waiting for one task to perform the others .
2-The Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
3-Because it represents the result of completing or failing a task and its value.
4-because we are waiting to a promise to give us its resulted value.
5-The first mistake is to not chain things together properly.
The second mistake is to nest unnecessarily, enabling the first mistake.
The third mistake is forgetting to terminate chains with catch.
6-use async/await over .then because async/await will pause the function execution until the promise settles. With then(), the rest of the function will continue to execute but JavaScript won't execute the .then() callback until the promise settles

@yousifr
Copy link

yousifr commented Oct 27, 2022

@Abdulbariii @MariaDaya
@marshallmhamad
@Yousif @huda
Maria, abdulbari, mohammed , Huda , Yousif.
1- Running along the program while running with the program it can respond to other tasks and events.
2- It's an object that represents the eventual completion of an asynchronous operation and it's value.
3- It's called a promise because it can be fulfilled or rejected or pending meaning that the operation could failed or could be successful, or could be neither failed or successful.
4- It's used to wait for the promise and get it's fulfillment value, it can only be used inside the async function.
5 - first mistake: creating a promise the forgetting to return it addition to unnecessary nesting of functions.
-So, try... catch can only handle errors that occur in valid code. Such errors are called “runtime errors” or, sometimes, “exceptions”

  • third mistake: in case there was runtime errors and the task did not execute then we will use the code inside the catch.
    6- Async/await will make your code more readable and cleaner, and the syntax will be more readable too , rather than using .then

@AmenCHW
Copy link

AmenCHW commented Oct 27, 2022

Hani, Zeynab, Shahla, Hogr, Ameen

1- if a function is asynchronous it will run other events while another event is still running and return the one that finishes first.

2- a promise is an object that returns a function if it succeeds or it will reject it and it's only used for asynchronous.

3- a promise is called that because you expect it either to be a success or a failure from an ongoing operation.

4- await will wait until we receive the result of the promise.

5- unnecessary nesting, no need for the curly brackets. we need to use try then if it fails you use catch. so the whole page doesn't crash and returns a backup code from the catch to inform the user that there is an error.

6- async/await will wait on the result of the promise and then continue with the function and this will reduce the chance of errors because it's better to get them in order for maintenance and readability.

@daliaJR
Copy link

daliaJR commented Oct 27, 2022

Team: [Batoul El Mansour, Ruba alsoheil, Dalia Jaber, Yahia hasan, Mahnaz Nazir, Omar Deeb]

  1. Asynchronous allow us to run multiple task at the same time even when we have a long running program rather than having to wait until that task has finished. Once it's finished the program will present the results

  2. promise is an object which help in the representation of the eventual completion or failure of an "asynchronous " operation.
    3)like the name implies, it means the guarantee of getting a return from the function. there are three states which are pending, fulfilled, rejected.
    4)Because it waits for a promise and get its value
    5)the error is being logged to console when writing code for Node.js, it's common that modules you include in your project may have unhandled rejected promises, logged to the console by the Node.js runtime. 

  3. Async/Await is used to work with promises in asynchronous functions. It is basically syntactic sugar for promises. It is just a wrapper to restyle code and make promises easier to read and use

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