Asynchronous Programming - Reading Assignment

1. What is the difference between synchronous and asynchronous functions?
Synchronous functions perform tasks sequentially, and cannot move on to the next task until the previous one is completed. Asynchronous functions, however, can initiate a task, and then put it aside for later while continuing to work on other tasks. For this reason, asynchronous code will not lock up the browser no matter how long it takes to complete.

2. What is callback hell?
Complex operations tend to require multiple levels of nested functions. Such code can become difficult for a human programmer to understand, and is thus known as “callback hell”.

3.Which technique can help us solve callback hell?
We can use “promises” to help us solve callback hell. JQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.

1 Like
  1. a task in JS that can be initiated and then put aside to complete later.
  2. VERY VERY Complex Functions with many inputs. AKA this:

How pretty am I right?

  1. Promises
1 Like
  1. synchronous functions occupy the javascript engine until they are fully executed, so you can only run one synchronous function at a time. Asynchronous functions allow us to start others functions while they are still running.
  2. making use of asynchronous behavoir often results in very complex code which is hard to read and understand.
  3. a common pattern to deal with excessive callbacks is to use promises.
What is the difference between synchronous and asynchronous functions?

Synchronous functions can only happen one after another, whereas asynchronous functions can execute in parallel.

What is callback hell?

Callback hell is a term used to describe multiple levels of nested functions.

Which technique can help us solve callback hell?

By use of the promises library that jQuery contains built in.

  1. Synchronous functions will run section of codes one at a time because it occupies full “attention”. Asynchronous functions can be put a side and be done at a later date so other code can be executed
  2. Callback hell is a term where you have an excessive amount of call backs within operations and nested functions.
  3. In the browser we can use promises to chain call backs. Or we can use the fiber package in Meteor. It extends the runtime so we can write code that abstracts away from a-synchronicity and looks synchronous.
  1. Synchronous functions will run and occupy the JavaScript engine until its completion, whereas asynchronous functions can be initiated and then put aside until a later point of time (to be called when a certain event occurs).
  2. When several callback functions are nested together and with that more and more levels and sub-levels are produced, the complexity also increases more and more, which is then poetically called callback hell. Visually this leads to a high level of indentation in the code.
  3. One common option to deal with callback hell is to use promises.
1 Like

What is the difference between synchronous and asynchronous functions?

Synchronous functions are functions queued for execution sequentially or one by one, execution flow is blocked while the function executes and completes. Asynchronous are functions that can happen any time and

What is callback hell?

Call back hell is when you have when you are expecting multiple callbacks and have no way of coordinating it or handling it in the best way possible, therefore hell.

Which technique can help us solve callback hell?

In javascript you can deal with it using promises where callbacks are chained together and error interception is made easier. Alternatively, Node.js can abstract callbacks to appear synchronous.

1 Like
  1. Synchronous functions require to be completely finished before the code and continue down the line. Asynchronous can be executed part of the way through and then be put aside until a later time to finish the function completely.
  2. Callback hell is a pit of many nested functions.
  3. One strategy is to use “promises” and another is to extend the runtime.
  1. In a single-threaded environment (JavaScript), only one section of code can be running at any one time. Synchronous functions occupy JavaScript continuously until its completion when asynchronous functions can be initiated and then put aside until a later event.
  2. Callback hell is a term to describe an operation which requires more levels of nested functions.
  3. We use promises to deal with excessive callbacks.

What is the difference between synchronous and asynchronous functions?
Synchronous functions: They need to be executed before proceeding to the next fuctions
Asynchronous Functions: While JS wait for a function to be executed, other functions can be executed a the same time.
What is callback hell?
complex operations tend to produce even more levels and sub-levels
Which technique can help us solve callback hell?
In the browser, a common pattern to deal with excessive callbacks is to use promises. jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors.

1 - Synchronous functions execute sequentially and will use up the JS engine until it is done running. Asynchronous functions can be initiated and then put aside to finish running at a later time.

2- The stacking of multiple asynchronous functions/instructions which can cause confusion to the developer and generate errors if not dealt with properly…

3 - jQuery can use Promises to deal more easily with multiple callbacks.

1. What is the difference between synchronous and asynchronous functions?
Synchronous flow in a single-threated predictable sequential path. Asynchronous can be multi-threaded, and exist in a parallel manner, and execute in a less predictable order

2. What is callback hell?
The more nested callbacks you have, the more complex managing/debugging them become.

3. Which technique can help us solve callback hell?
In the browser, a common pattern to deal with excessive callbacks is to use promises. jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors. But in Node.js, we can use a different approach. By extending the runtime, we can abstract away the asynchronicity and write code that looks sychronous.Synchronous flow in a single threated predictable sequential path. Asynchronous can be multithreaded, and exist in a parallel manner in a less predictable order

  1. While JavaScript will faithfully follow every one of our program orders, it can only take care of one task at a time. In a single-threaded environment, only one section of code can be running at any one time. Even though multiple event handlers run on the same event, all handlers other than the first won’t run until the first handler has completed. The browser won’t respond to any events whatsoever while it completes the first handler. Tasks like these are called blocking or synchronous. Whereas a synchronous task will occupy Javacript continuously until its completion, an asynchronous task can be initiated and then put aside until a later date while Javascript gets started on the next task on his to-do list. This to-do list is called the event loop.

  2. The JavaScript engine sports an additional background thread which takes care of managing this event loop. We now have two event handlers; the first handler sends a request and schedules the second handler to run when that request comes back. The second handler is known as a callback, and instead of responding to the first event, it will respond to a special event fired by the browser. On the server, the Node.js runtime is single-threaded as well. But in Node.js, you’ll likely come across many more asynchronous operations: calling APIs, reading and writing files, executing operations on the server, etc. This time, we’ve set up three nested functions: our main trackUser function, one for looking up the user in the database, and one for inserting a new record. This requires multiple levels of nested functions. More complex operations tend to produce more levels and sub-levels, which is what is poetically known as callback hell.

  3. In the browser, a common pattern to deal with excessive callbacks is to use promises. jQuery ships with a simple built-in promise library that enables us to chain callbacks and deal with errors. But in Node.js, we can use a different approach. By extending the runtime, we can abstract away the asynchronicity and write code that looks synchronous.

1. What is the difference between synchronous and asynchronous functions?

The difference is that in a synchronous function, a task will continuously occupy the browser until it’s completed.

Whereas in an asynchronous function, a task can be started and then put aside until a future time, whilst another task is started.

2. What is callback hell?

Callback hell is where more difficult operations tend to produce even more levels and sub-levels.

3. Which technique can help us solve callback hell?

The promise technique can help us solve callback hell.

  1. Synchronous functions block the execution by waiting for a task to complete and async functions just start a task and wait for an event notifying that the task has completed.
  2. Callback hell is a situation when you have nested async function calls and therefore code becomes very complicated to read.
  3. We can chain callbacks and deal with errors that way or we can use other special libraries that were designed to simplify async programming by allowing sync style code.
  1. What is the difference between synchronous and asynchronous functions?

Synchronous functions are blocking the browser until they have finished to run while asynchronous functions allow for other operations to happen while the function is executing.

  1. What is callback hell?

Callback hell refers to the proilferation of nested callbacks when complex tasks have to be handled in an asynchronous way.

  1. Which technique can help us solve callback hell?

Using promises can help us solve the callback hell problem. A promise represent the result of an asynchronous operation and can be used instead of a callback while processing error handling at the same time.

  • What is the difference between synchronous and asynchronous functions?
    If they use one or many threads

  • What is callback hell?
    You setup a job and move on, when done you receive a notification, hell apears when this grows out of control

  • Which technique can help us solve callback hell?
    Promises

  1. What is the difference between synchronous and asynchronous functions?
    

synchronous - execute a single instance and cannot do anything else while the result is being computed.

asynchronous - you execute a call, typically along with an event listener that waits for something to happen to finalize the execution of the function. This can run in the background while other synchronous events happen.

  1. What is callback hell?
    

using so many nested functions that you end up in a continuous looping function that calls other functions and loops forever or returns unexpected results.

  1. Which technique can help us solve callback hell?
    

promises - with jquery

What is the difference between synchronous and asynchronous functions?
in synchronous functions we have a hierarchy of functions executed one by one. asynchronous functions can be executed simultaneously / perform multitasking.
What is callback hell?
function inside of a fucntion inside of another function and so on
Which technique can help us solve callback hell?
promises

What is the difference between synchronous and asynchronous functions?
synchronous is single threaded one-at-time task handling.
asynchronous is where you can fire of a request for data and continue with other tasks while you wait for the data to come back.

What is callback hell?
Many sub levels of nested functions requiring callbacks that have become unweildy

Which technique can help us solve callback hell?
Promises…
A promise is asychronous action in one of three different states:
pending - The initial state of a promise.
fulfilled - The state of a promise representing a successful operation.
rejected - The state of a promise representing a failed operation.

1 Like