Asynchronous Programming - Reading Assignment

  1. Synchronous functions can only be executed one at a time by the engine. Asynchronous functions, instead, can run in background while the main thread is performing other operations.
  2. Callback hell is the complex structure (with multiple levels of nested functions) that asynchronous functions can have in contexts of a certain complexity.
  3. We can use promises such as the ones in the Fibers package, which -among the other features- allows writing asynchronous functions in a synchronous style.
1 Like

Asynchronous Answers

1.Synchronous function occupies all of Javascript’s attention, each executing line of code line by until completion. While Asynchronous functions allow for the initialization of another task to be called at a later point while it completes its main thread or current task.

  1. Because even relatively simple operations can use two or three layers of nested functions, with the more complex operations it quit simple to produce more layers and even more sub-layers of those layers producing what is called “callback hell”.

  2. A common pattern to deal with excessive callbacks is to use promises which is a simple built-in library in javascript that enables us to chain callbacks and deal with errors.

  1. Synchronous functions block the further execution of a program until something is done, whereas asynchronous functions do not block the program and wait while the program executes other tasks.
  2. Callback hell is a situation when many asynchronous functions are held up by waiting for other nested functions to finish with execution, essentially holding up the whole process.
  3. Promise allows us to chain callbacks and handle errors.
1 Like

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

    1) Synchronous: Any validation you want to perform before the form submits on client side.   For ex you want to check if a field on other table has data or not   for this you will make a Synchronous Ajax call to get the Data from Server Side to client and based on response you may submit the record or return false.


    2)Asynchronous: If you need to perform any server side action and there is no need to show anything on current form . i.e. for any background server actions you can use Asynchronous Ajax



b. What is callback hell?

    Callback hell is a situation in Javascript when you face callbacks within callbacks or nested callbacks.




c. Which technique can help us solve callback hell -->

    There are two significant ways to avoid Callback Hell in NodeJS:
    1. Using Promises
    2. Use Async/Await
1 Like

Homework on Asychronous Programming - Questions January 14th , 2021

  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions are code executed in a series. Asynchronous functions are multiple codes executing at once.

  2. What is callback hell?
    Callback taken fron a argument, resulting from a previous callback. This is found in
    complex nested codes.

  3. Which technique can help us solve callback hell?
    In Javascript you can use a promise. This will allow to produce a value in the near future.

-Hector A. Martinez

1 Like

1. What is the difference between synchronous and asynchronous functions?
The synchronous function occupies javascript’s attention continuously until completion, whereas an asynchronous task can operate in the background, allowing the next task in javascript to be initiated.
2. What is callback hell?
Callback hell is the problem of overly complex operations that have multiple layers of nested functions, creating levels of sub-levels.
3. Which technique can help us solve callback hell?
By implementing jQuery’s built-in promise library we can deal with the chain callbacks and any errors we run into. Thus resolving the callback hell conundrum.

1 Like

1.- What is the difference between synchronous and asynchronous functions?
Synchronous functions happen one by one. Asynchronous functions are executed in parallel an the put aside while other functions are running in the main thread.
2.- What is callback hell?
Callback hell defines an asynchronicity situation of several levels of nested functions placed to perform different tasks.
2.- Which technique can help us solve callback hell?
“Promises”. That is a way to chain callbacks and deal with errors

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous is single threaded and can manage only one function at a time where asynchronous can execute multiple functions at any time and may be delivered in the future.
  2. What is callback hell?
    Spahgetti code supporting async I/O calls caused by poor coding practices.
  3. Which technique can help us solve callback hell?
    Modularize.
1 Like
  1. synchronous functions or blocking functions are functions they only run one at a time, the browser won’t respond to any other events while this function is running in a single-threading environment.
    asynchronous functions will be initiated in the background and then set aside while other tasks are being completed, only to restart and save time.
  2. callback hell refers to the deep levels and sublevels of nested functions required to operate one main function, continuously calling back to themselves.
  3. Packages like fiber allow us to write asynchronous code in synchronous style, using a sub-library that works similar to jquery.
1 Like
  1. synchronous functions will occupy until it’s completed but asynchronous functions can be initiated then put aside for a later date.
  2. callback hell is an excess of functions performed in nested form
  3. promise
1 Like
  • What is the difference between synchronous and asynchronous functions?
    Synchronous can only be done if a block has finished executing while asynchronous functions can multitask by being initiated and then is put on hold until it is called again to run.

  • What is callback hell?
    When there is multiple complex operations that many levels to it.

  • Which technique can help us solve callback hell?
    Promises.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions can not run at the same time. They will block anything else from being executed until they are finished.
    Asynchronous functions can allow other tasks to be run at the same time the async function is executing.

  2. What is callback hell?
    In an Asynchronous function you wait for a callback which triggers the end of the function. Writing out an async function takes more space and looks more complex since you need to include some information about the callback (vs a sync func which doesn’t need a callback). Callback hell is when you have some system of async functions nested in each other where each level needs its own callback. You are in callback hell because of all the callback code you had to write out.

  3. Which technique can help us solve callback hell?
    For Javascript you can use Promises which is included in JQuery
    For NodeJS you can use Meteor and the Fibers package.

Both will make the code look ‘sync-like’ but will maintain the async properties.

1 Like

1.) JavaScript runs on synchronous functions. For instance, when you call two actions to happen for clicking your mouse button, the program will execute one function before executing the other. Asynchronous functions can be initiated and left alone until it fully executes.
2.) Complex operations that produce multiple levels and sub-levels of nested functions is known as callback hell.
3.) With promises (a built-in jquery library that enables us to chain callbacks and deal with errors) or by extending the run time.

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

A synchronous function is when Javascript has to run through all the code to execute a function. An example of this might be when it is waiting on an input from the user before executing all of the code. An asynchronous function is when Javascript puts the function aside and performs or accesses it later.

  1. What is callback hell?

Complex operations that produce more and more levels and sub-levels of what you are asking the JavaScript code to do.

  1. Which technique can help us solve callback hell?

Using Promises. JQuery has a simple built-in promise library that enables us to chain callbacks and deal with errors. In node.js we can abstract away asynchronicity and write code that looks synchronous.

1 Like
  1. Synchronous functions execute one by one, so that only one gets executed at a time. Asynchronous functions don’t wait for another function to finish before starting.
  2. Callback hell is when functions are nested within other functions creating a potentially messy situation.
  3. promises can help with callback hell.
1 Like
  1. Synchronous functions can execute a single selection of code at any one time and cannot move on to the next task until the previous one is completed. Asynchronous functions, however, can initiate a task and set aside to execute the callback at a later time while continuing to work on other tasks. Asynchronous code will not lock up the browser no matter how long it takes to complete.

  2. Callback hell is a problem when executing many nested functions and it becomes difficult for a programmer to understand.

  3. We can use promises to chain callbacks or we can use the fiber package in Meteor. By extending the runtime, we can write code that abstracts away from a-synchronicity and looks synchronous.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions are when you have multiple functions that act at the same time(e.g. after an event handler). The program will execute the first function and be stuck on it until it’s completion and it can move on. Asynchronous functions can put a function aside and move on, even though the first function it encountered isn’t completely finished.

  2. What is callback hell?
    Callback hell is where there are many different levels and sublevels of operations and functions in the code. It occurs when there are multiple nested if statements or functions that are complicated and difficult to read.

  3. Which technique can help us solve callback hell?
    Promises are a method of solving callback hell. They extend the time to run the code slightly so that the code appears to run synchronously even though it’s not.

1 Like

What is the difference between synchronous and asynchronous functions?
What is callback hell?
Which technique can help us solve callback hell?

  1. A synchronous function occupies the program’s resources continuously until the task is completed, whereas asynchronous functions can be revisited when ready.

  2. Callback Hell is a result of badly written code, creating a confusing tangle of hard-to-read programming. Nested functions get out of control quickly.

  3. Writing more modular code - rather than putting too many functions in large blocks. Also, using ‘promises’ in the code. This can be done using libraries for JS. Promises allow for effective asynchronicity in JS.

1 Like
  1. Synchronous functions will execute consecutively and prevent other functions from executing until the previous function has been finished. Asynchronous functions can run in the background while other functions are being executed.
  2. Callback hell refers to having numerous levels and sub-levels of nested functions for complex operations.
  3. Excessive callbacks from asynchronous functions are managed with the use of promises. jQuery has a built-in method called “.promise()” that enables dealing with errors and chain callbacks together.
1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous functions- Run consecutively and block other functions from executing until the previous function is completed.
    Asynchronous functions- Can run in the background while other functions are executed.

  2. What is callback hell?
    simple operation requires three levels of nested functions.
    More complex operations tend to produce even more levels and sub-levels, = callback hell.

  3. Which technique can help us solve callback hell?
    In the browser the 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.
    In Node.js a different approach is used by extending the runtime, we can abstract away the
    asynchronicity and write code that looks sychronous.

1 Like