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?
@ninaderochka
Copy link

ninaderochka commented Oct 27, 2022

Aland - Nma - Ali Majid - Sara Bakr - Nina - Fadi

  1. It's a function that doesn't return something until the whole code is completed.
  2. A promise is an object that represents the failure or success of an asynchronous function.
  3. Similar to its meaning in English, a promise resolves an outcome if its true and it rejects the outcome if it's false.
  4. Await, waits from the promise and then gets the result of the promise.
  5. Common mistakes:
    First mistake - forgetting to return a promise of an asynchronous function.
    two chains of events will cause some errors
    Second mistake - nesting unnecessarily enables the first mistake.
    Third mistake - forgetting to terminate chains with catch. (catch is for error)
  6. difference is that in an async function and await, JavaScript 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.

@Hala-AlArid
Copy link

Hala, Rozhiar, Mustafa, Wafaa, Danah

1- it is a technique we use for a function that will run other parts of the program until that function finishes

2- it is an object that represents the callback function.

3- it is called a promise because it promises to return value/do work at some point even when there is no immediate callback

4- it is called await because it will wait for the server to load our data/ wait for the piece of code to run before giving us the result

5- most common mistakes are:

  1. forgetting to return a promise
  2. do unnecessary nesting
  3. Forgot to terminate chain with a catch

6- Async/await and then() are very similar.
The difference is that in an async function, JavaScript will pause the function execution until the promise settles. With then(), the rest of the function will continue to execute but JavaScript will wait the .then() callback until the promise settles.

@bluesky1992-web
Copy link

bluesky1992-web commented Oct 27, 2022

team : Ahmad Hassoun , Banel Mkhael , Sakar Masoud , Nanor Gosdanian , Roza Nawzad , Ali ibrahim

Q1: asynchronous means excuting an operation while waiting for other operation to be done.
Q2 , Q3: A promise in JavaScript is an object that is returned after an asynchronous operation. The object will be returned regardless of whether the asynchronous operation was a success or failure. This is why it is called a promise.
also promise is represents an operation that hasnt completed yet

Q4: The await operator is used to wait for a Promise and get its fulfillment value.
Q5: 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.

Q6: Async/Await makes it easier to write promises. The keyword 'async' before a function makes the function return a promise, always. And the keyword await is used inside async functions, which makes the program wait until the Promise resolves.

Async/await and then() are very similar. The difference is that in an async function, JavaScript 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.

@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