Asynchronous Programming - Reading Assignment

  • 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
  1. Synchronous functions run sequentially “top to bottom”. While asynchronous functions can “jump around” allowing them to initiate or not.
  2. Complex operations with many levels and sub-levels
  3. Promise Library in jQuery.
1 Like

**What is the difference between synchronous and asynchronous functions?
Synchronous functions have only one task in it, but asynchronous functions have more than one task in it.

**What is callback hell?
Callback hell in which has several functions and the relation between them are interrelated.

**Which technique can help us solve callback hell?
Promise libaray

1 Like
  1. Synchronous functions does not return until the work is completed or has failed. It waits for each operation to complete, after that only it executes the next operation. Meanwhile an asynchronous functions usually can be initiated and then put aside until a later date and it never waits for each operation to complete, rather it executes all operations in the first only. The result of each operation will be handled once the result is available.

  2. It’s an anti-pattern seen in code of asynchronous programming. It consists of multiple nested callbacks, which makes code hard to read and debug. For example with simple operations, which require three levels of nested functions, while more complex operations tend to produce even more levels and sub-levels.

  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 sychronous.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    A Synchronous function uses a single-threaded command to execute two events, those handlers are completed one at a time. An Asynchronous function can initiate other tasks while still holding for completion or feeding by the user of a previous handler.

  2. What is callback hell?
    Is when multiple layers of asynchronous nested functions generate revolving callbacks. It compromises smoothness and might asks for more maintenance.

  3. Which technique can help us solve callback hell?
    JQuery built-in library, Fiber, and Meteor allows multiple callbacks running as asynchronous functions.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Usynchronous functions can be interrupted by another task and synchronous functions complete to the end without interruptions.
  2. What is callback hell?
    It makes code difficult to understand because of the complex amount of function nesting.
  3. Which technique can help us solve callback hell?
    By using promises.
1 Like
  1. Synchronous Functions block the program until they are completely executed whereas asynchronous functions need not wait for first task to be completed and can perform next task and come back again when the first one is complete.

  2. Callback hell is when we need several nested functions in order to perform simple tasks.

  3. Promise can solve this situation by enabling us to chain the callbacks and dealing with errors.

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

Only one task can be done at a one with synchronous functions , while asynchronous task can be initiated and then put aside until a later date while other tasks are being completed.
2. What is callback hell?

Too many if statements and functions causing your javascript to have looping issues.

3.Which technique can help us solve callback hell?
Promises are used to check for errors that can lead to callback hell. It is usually shipped in a built in library in jQuery.

1 Like

1. synchronous operations block instructions until the task is completed, while asynchronous operations can execute without blocking other operations.

2. In computer programming , a callback , also known as a “call-after” function, is any executable code that is passed as an argument to other code that other code is expected to call back (execute) the argument at a given time.

3. Promises are used to solve the call back hell situation

1 Like

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

Synchronous function run one section of code at any time .
Asynchronous functions run more than one section at any one time.

2.What is callback hell?
It s a situation where several functions are performed in nested form.

3.Which technique can help us solve callback hell?
Promises are used to solve callback hell.
There are also options in different applications to solve callback problem .

1 Like
  1. A synchronous function will block execution until it is completed, then the next function will be excuted.
    An asynchronous function will execute what it can then allow execution to move to another function, the original function’s execution will be completed in a callback

  2. Callback hell refers to multiple nested asynchronous functions

  3. jQuery uses promises to solve callback hell by chaining callbacks and handling errors, and Node.js simulates synchronicity by letting us write code in a synchronous style with synchronous control flow.

1 Like