Asynchronous Programming - Reading Assignment

1. What is the difference between synchronous and asynchronous functions?
Synchronous function will run statements in sequence one after the other. It will not move on until each statement is completed in order.
Asynchronous function will put a statement aside and allow you to progress while simultaneously waiting for that that statement to complete. Allowing the code to appear to run out out of sequence.
2. What is callback hell?
Multiple levels and sub levels of nested functions
3. Which technique can help us solve callback hell?
In JQuery we can use promises
in Node.js we can use Meteor-Fibers package

1 Like

What is the difference between synchronous and asynchronous functions?
a synchronous function will occupy javascript continuously until its completion.
An asynchronous function can be initiated and then put aside until a later, while our
program gets started on the next task in our code.

What is callback hell?
relatively simple operations may require multiple levels of nested functions, more complex operations tend to produce even more levels and sub-levels, which is known as callback hell.

Which technique can help us solve callback hell?
Construct a promise; The Promise object is used for asynchronous computations. A Promise represents a value which may be available now, or in the future, or never.

2 Likes
  1. The difference between synchronous and asynchronous functions is that synchronous functions have to be completed in order, and they wait for each other to complete to start the next one, while asynchronous functions can be initiated and put on hold until later, so that the JavaScript engine can do other tasks simultaneously.
  2. Callback hell occurs when you have excessive asynchronous functions with callbacks in your code, which make the code overly complex and difficult to read.
  3. To deal with callback hell, we can use different techniques depending on if we are running in the browser or in node.js. In the browser, we can use promises, which is a built in library in jQuery that enables us to chain callbacks and deal with errors. In node.js, we can use the Fibers package. Fibers allow us to write asynchronous code with synchronous style.
1 Like
  • What is the difference between synchronous and asynchronous functions?

Synchronous functions need to be executed from top to bottom when called, asynchronous having a statement that if this event happens then execute function.

  • What is callback hell?

Callback hell is when your asynchronous code is hard to read and debug.

  • Which technique can help us solve callback hell?

Promises

doSomething()
.then((response) => doSomethingElse(response))
.then((secondResponse) => doAThirdThing(secondResponse));

// Even cleaner
doSomething().then(doSomethingElse).then(doAThirdThing);

But as with everything, promises were not perfect either. So, as part of the ES2017 Specification, another method for dealing with synchronous code was defined; asynchronous functions. These allow us to write asynchronous code as if it were synchronous.
SRC:Bitsofco

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions must wait for the last function to finish before preforming the next.
    Asynchronous functions can initiate put aside and wait for an answer or result while going on to execute other functions

  2. What is callback hell?
    Multiple callback functions nestled inside other functions, which can quickly become extremely hard to understand.

  3. Which technique can help us solve callback hell?
    By using the promises library in jQuery to chain callbacks.

1 Like

What is the difference between synchronous and asynchronous functions?

Synchronous functions gives a direct respons when called. It does the steps one by one (single threaded). Asynchronous functions build in time so other tasks can be executed when the functions have to wait for being executed (for example: data that have to be collected en come back to the function).

What is callback hell?

Many asysnchronous operations could contain several functions each. This makes the executionproces complex when the functions are excessively called within the operations in a short period of time.

Which technique can help us solve callback hell?

We can use “promises.jQuery”. It is a built-in promise library that enables us to chain callbacks and deal with errors.

2 Likes
  • Synchronous functions occupy the JS engine and asynchronous functions are waiting for their time to operate
  • Where we use nested callback functions to make simple tasks. It takes time, harder to write and debug
  • The use of Promises can solve a callback hell situation
1 Like

1: synchronous functions block the program to be executed further until they are finished. asynchronous functions don’t block the program while the program thread does another task
2:callback hell is when there is a callback inside a callback inside a callback,…
3:the use of Promises can solve callback hell.

1 Like
  1. synchronous funections must be executed and completed during the code execution thread, so while the function is working, the execution of the code must wait for the function to finish. Whereas, asynchronous functions are functions that get initiated and the rest of the code thread can keep going while the asynch function does it’s computations.

  2. callback hell is a nest of callback functions, one inside of another inside of another etc. It is difficult to read because of it’s multiple nesting structure.

  3. promises solve the callback hell problem because instead of nesting callbacks, they can be written linearly, and also allow for handling of successful vs failure outcomes of the callbacks.

1 Like
  1. Synchronous functions are tasks within the code that will require the program’s full attention until they are completed. On the other hand, asynchronous functions can be initiated as tasks to complete, but can done in the background until they are completed, allowing the code to continue executing its tasks.

  2. Callback hell is when there are excessive amounts of functions and sub-functions trying to be executed, and it creates a big mess.

  3. To solve callback hell, we can use promises or Fibers, which takes an asynchronous function and creates an equivalent code with a synchronous style.

1 Like
  • What is the difference between synchronous and asynchronous functions?

synchronous is single threaded and can only do one job (function) at a time
an asynchronous task can be initiated and then put aside until a later date while our
programm gets started on the next task on the to-do list.

  • What is callback hell?

more complex operations tend to produce even more levels and sub-levels of nested functions, which is known as callback hell. It makes the code hard to maintain as it gets complex real fast

  • Which technique can help us solve callback hell?

Using promises:

What is a promise?

The core idea behind promises is that a promise represents the result of an asynchronous operation. A promise is 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.

Once a promise is fulfilled or rejected, it is immutable (i.e. it can never change again).

1 Like
  1. Synchronous functions are executed instantly, an asynchronous functions can be initiated and then put aside until a later date.
  2. Asynchronous functions callbacks on more levels and sub-levels.
  3. To deal with excessive callbacks is to use promisesa, a simple built-in library that enables us to chain callbacks.
1 Like
  1. Synchronous functions occur in a given order, one at a time and block the program from executing subsequent tasks while they are being worked on. Asynchronous functions can be happening simultaneously while waiting for other events to occur.

  2. More complex operations can result in too many nested functions, resulting in undesirable callback hell.

  3. We can use promises that come from various promise libraries.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
  • Synchronous functions are executed one at a time. While the current one is not finished, a new one won’t be called. Like with alert, you cannot interact with a webpage until you click the button.
  • Asynchronous functions can be initiated and then put aside, leaving space for other functions to run. Later, when some event happens (e.g. data arrives or user inputs something), they get finished. To keep track of initiated functions, Javascript runs a background thread called Event Loop.
  1. What is callback hell?
  • As we may create functions in functions, or functions that depend on other functions, there could be many levels of asynchronous functions waiting for some event. That is called callback hell.
  1. Which technique can help us solve callback hell?
  • Promise method. It returns a promise that is resolved when some condition is met. jQuery comes with a promise library.
  • In Node.js we can extend runtime to make asynchronous functions abstractly synchronous. That is, we specify that the function will be executed after some time, assuming that this time is enough for the necessary conditions to be met.
1 Like

1.What is the difference between synchronous and asynchronous functions?
In a synchronous programming model, things happen one at a time. The solution to this problem, in a synchronous system, is to start additional threads of control. A thread is another running program whose execution may be interleaved with other programs by the operating system—since most modern computers contain multiple processors, multiple threads may even run at the same time, on different processors. An asynchronous model allows multiple things to happen at the same time.
Another way to describe the difference is that waiting for actions to finish is implicit in the synchronous model, while it is explicit, under our control, in the asynchronous one.
2.What is callback hell?
A relatively simple operation may require several levels of nested functions. More complex operations tend to produce even more levels and sub-levels, which is what is poetically known as callback hell.
3.Which technique can help us solve callback hell?
In the browser, a common pattern to deal with excessive callbacks is to use JQuiry library called promises. jQuery has a built-in promise library that enables us to chain callbacks and deal with errors.

1 Like
  1. synchronous task occupies a lot of memory until the task is completed while asynchronous task will initiate but finish at a later time
  2. This looks like hell
               }
             })
            })
           }
         })
        }
      })
    })
  }
})
  1. Using promises jQuery sends a built in promise to library application that allows callbacks and deals with errors.
1 Like

1 synchronous function will execute one task at a time while asynchronous function can start a task, leave it in stand by, continue with a new task and go back to the previous one when it’s possible.

2 when there are many call back (many nested functions)

3 callback hell can be managed with built in promise library

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

Synchronous tasks are tasks in JS that occupy the full attention of the events handler.

Asynchronomous function allows the event handler to do other functions while it waits for answers.that event and then return

  1. What is callback overload? Complex operations that tend to produce levels and sub-levels of nesting functions.

  2. Which technique can help us solve callback overload? The use of promises, which chains callbacks and deals with errors can help prevent callback overload. Node.js also extends the run-time, and abstracting away asychronicity, and write code that looks syncronous. The fibers package in Metior does this behind the scenes.

2 Likes
  1. synchronous fuctions need to be completed before another part of the code can be executed while asynchronous fuctions allow for other parts of the code to execute while they wait for a response to something in order to be completed.

  2. because JavaSript is synchronous - single threaded - in order to make a functional asynchronous code the callback function is required and as many callback functions get nested inside each other complexity and increases and errors become hard to trace, this is called callback hell.

  3. on node.js we can extend the runtime thus abstracting away the asynchronicity and we can write our code in a sychronous style. while in the browser we can use promises such as the ones built-in to the jQuery library.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions must be executed before moving on to the next function
    Asynchronous functions can start and then be put aside and finished later
  2. What is callback hell?
    When there are too many callback functions inside of one another
  3. Which technique can help us solve callback hell?
    Promises library in JQuery which allows programmer to simplify code
1 Like