Asynchronous Programming - Reading Assignment

  1. Synchronous functions tie up a a single thread whilst asynchronous allows the thread to move on and wait for a response, not locking up the browser or server.

  2. The deep listing of asynchronous functions that make it pretty hard to code for.

  3. Abstraction with libraries or “promises” allows people to code synchronous functions that behave asynchronously

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

Synchronous functions occur one after the other and don’t allow the next function to begin executing until the previous one has finished.
Asynchronous functions on the other hand will allow other functions to begin before it has completed all of its tasks.

  1. What is callback hell?

Callback hell occurs when you have an excessive number of callbacks (functions) nested within one another, making the code overly complex to manage.

  1. Which technique can help us solve callback hell?

We can use the promises library that jQuery contains built in, that enables us to chain callbacks and deal with errors.

1 Like
  • What is the difference between synchronous and asynchronous functions?
    • Synchronous functions can only be carried out one at a time, they occupy JS’s full attention capacity
    • Asynchronous functions can be initiated, then put aside for later, freein JS up to carry out other tasks
  • What is callback hell?
    • Code that has excessive amounts of nested functions
  • Which technique can help us solve callback hell?
    • Promises enables programmers to chain callbacks n deal w/errors
    • In Node.js, we can extend the runtime

@LORDKALVIN

1 Like
  1. Synchronous functions are executed in full in a particular order before moving on to another element to execute; this can cause delays in the broader program execution if one element is taking time. Asynchronous functions allow for a task to be executed and then put aside while other tasks are executed, allowing for less bottlenecks or faster execution.
  2. Callback hell is a situation when you may have a plethora of nested functions, resulting in excessive callbacks.
  3. Promises can be used to deal with excessive callbacks.
1 Like
  1. synchronous is like javes is doing 1 thing at a time, like if you are taking a poo,
    you cant answer the telephone at the living area, so you have to do things 1 step at a time.

asynchronous is where javes can do multitasking, im not really sure if its multitasking, but its like
if your sending your resumes for a job opening, and while waiting, you send more to other job openings.

  1. callback hell is about nested functions, the more complex the operations are and being harder and harder to analyze,
    its like we are being called back to hell.

Oh thats why I feel so hellish if I don’t understand fully the code, tbh I feel it almost everytime,
but you guys said if google can answer it, you solved it, but i want to realy learn how to imagine and code it. pls help me

  1. we can deal with excessive callbacks by using promises, node.js use an approach by extending the runtime,
    it can abstract away the asynchronicity and write code that looks synchronous. Meteor uses Fibers package to make the database code look simpler and easy to analyze.
1 Like
  1. Synchronous - the tasks are completed one at a time going down the code.
    Asynchronous - is able to move between tasks even if the previous one is not completed.

  2. It is known when there are many nested functions. This creates complex code and creates many call backs for the code to operate.

  3. Promises - is used for excessive callbacks, a built-in system with JQuery. Or in Node.js you can extend the runtime trick the code from looking asynchronous to synchronous.

1 Like
  1. Synchronous functions - will execute continuously until its completion one by one, no multitasking involved. Asynchronous functions - is more multitasking/parallel in the sense that they send the request and free the program execution until they are called back.

  2. Callback hell - A callback is the function we give to an event. can be chaotic in which the callbacks are nested within each other like event handlers. This makes the code more complex.

  3. To solve Callback hell, use of promises.

1 Like
  1. Synchronous functions is function in a single threaded environment. This represents performing one task at a time and only moving on to the next task when the current one has been completed.
    Asynchronous functions can be started and then set aside to be completed at a later time while the program moves on to performing other tasks such as loading up of a video file while the program is fetching data from an external API.

  2. When a program becomes complicated due to a number of nested functions that increase in size with the increase in a programs complexity. Thus as a call back is a function we give to an event, more nested callbacks end up creating a call back hell.

  3. The technique to solve call back hell is to use Promises. A promises library is included as part of JQuery i.e it is built in. Promises allows the use to create a chain attaching all the call backs so we know they are part of a single program/command and help us reduce call back errors.

1 Like

[quote=“ivan, post:1, topic:3128, full:true”]
Welcome to the discussion about the reading assignment about asynchronous programming.

Leave your answers to the questions below in this thread. If you have any questions or you want to discuss something connected to the assignment feel free to do it in this thread as well, but please everything to the topic.

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

In synchronous operations tasks are performed one at a time and only when one is completed, the following is unblocked. In other words, you need to wait for a task to finish to move to the next one.

In asynchronous operations, on the other hand, you can move to another task before the previous one finishes. This way, with asynchronous programming you’re able to deal with multiple requests simultaneously, thus completing more tasks in a much shorter period of time.

  1. What is callback hell?
    It is a concept that affects a JavaScript developer when he tries to perform various callbacks function one after the other.
    Using callbacks causes the program difficult to write and maintain. It also increases the problems of identifying the order flow, which is an obstacle when debugging, hence the famous name for this issue: Callback Hell.

  2. Which technique can help us solve callback hell?
    Promises are an option to callbacks when interacting with asynchronous code. Promises return the result value or an exception to a mistake. The heart of the promises is the.then() function, which waits for returning the promise object. The.then() function requires two optional functions as arguments and only one will ever be called depending on the state of the promise. The first method is called when the promise is fulfilled. When the promise is rejected, the second function is called.

1 Like
  1. synchronous Function waits for a task to be done before running. asynchronous Function will run even if the task set before it completes

2.Callback within a callback and several function being called

  1. Promises
1 Like
  1. asynchronous functions can be initiated and executed at a later time, while synchronous functions require to be executed in their entirety with full attention.
  2. Callback hell is excessive callbacks or nested levels of functions in an operation.
  3. This is the use of promises using jQuery in a browser through a promise library.
    However, in Node.js we extend the runtime and change the code a little to make asynchronous functions look as if they are synchronous.
1 Like

1. What is the difference between synchronous and asynchronous functions?
Synchronous - Only one segment of code can be running at a time
Asynchronous - A segment of code can be ‘put on hold’ while another section completes and then the ‘on hold’ section can complete

2. What is callback hell?
Callback Hell is when multiple asynchronous functions are waiting for other functions to complete before being able to process.

3. Which technique can help us solve callback hell?
Promises - multiple javascript libraries, such as jQuery and Angular come with promise libraries.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    When you call the asynchronous function your program will wait for a response before it can continue executing. However, an asynchronous function does not provide an immediate response and will therefore allow the calling code to continue executing whilst the function executes in a different thread.

  2. What is callback hell?
    Callback hell is an abstract problem, which creates the problem of the readability of the code. More complex functions require more levels of code, and each level could require more callback functions. It creates unnecessary complexity with a clutter of all callback functions, whose sole purpose is to call back when the request is ready.

  3. Which technique can help us solve callback hell?
    One of the ways to deal with is promises supported by built-in Library, another way is to use Fibers of Node.js.

1 Like

1- Synchronous functions block the program’s further execution until something is done while Asynchronous functions do not block the program and wait while the program thread does other task.
2- Callback hell is a situation where several functions are being performed in nested form.
3- Promise is used to solve the call back hell situation. jQuery, AngularJS come with promise library. It also handles errors.

1 Like
  1. In synchronous function program waits for a response before it can continue to the next part of the code. While in asynchronous functions can be initiated and then put aside until a later date while our valet gets started on the next task on his to-do list.
  2. More complex operations tend to produce more levels and sub-levels, which is what is poetically known as callback hell.
    3.We can deal with it via promises supported in Library, or use Fibers of Node.js
1 Like
  1. Synchronous functions run at an orderly runtime, so one only runs at the end of the other. Asynchronous functions allow changing the order of execution of tasks by managing the events in ‘background’. Through them, tasks can be interrupted and set aside while another will be performed.

  2. ‘Callback hell’ consists of over-nesting asynchronous functions. This generates a truly complex and difficult to understand pyramid, in which a code can only be executed as a condition of having returned certain previous answers.

  3. In the browser, a common pattern for handling excessive callbacks is to use the ‘promises’ system. This is a way to organize and string together subsequent callbacks, through .then and .catch blocks (for example). In Node.js, we can use simulated synchronization. That’s what Meteor (a specific node.js-based framework) does behind the scenes using the Fibers package.

1 Like
  1. What is the difference between synchronous and asynchronous functions?
    Synchronous tells JavaScript to run the code in order from top to bottom. Asynchronous tells JavaScript to callback part of the code at a later time.

  2. What is callback hell?
    Call back hell is when multiple callbacks are initiated and create conflicts between each other.

  3. Which technique can help us solve callback hell?
    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 Like

1: Synchronous functions must be completed before moving on to execute other code, while an asynchronous function can
be initiated and finished at a later time.

2:
Complex operations with multiple levels of nested functions that recall each other and can cause code to become unreadable.

3:
Using promises.

1 Like

1. What is the difference between synchronous and asynchronous functions?
Synchronous functions occupy JS continuously until their completion. On the contrary asynchronous ones can be initiated and then put aside until later, while JS starts working on the next task. Asynchronous tasks are usually API calls or queries to 3rd party services for data.

2. What is callback hell?
Callback hell is an issue of asynchronous programming, caused by complex nested callbacks, making the code difficult to read and maintain. Also if there is an error in one of these callback functions, the rest of the functions will be affected.

3. Which technique can help us solve callback hell?
There are at least 3 ways to fix this issue:

  1. Promises- use .then method to escape the nested structure. The code gets much cleaner and easier to understand.
  2. Comments, explaining each step of nested callbacks.
  3. Async/Await syntax to make asynchronous code look like synchronous.
1 Like

What is the difference between synchronous and asynchronous functions?

Synchronous functions take all of the attention, they are running at the front and not allowing to do other things beside that, while asynchronous functions are running on the “backoffice, and we can do other tasks at the same time.

What is callback hell?

Callback hell is to recursive nesting of callback functions that can be complicated to handle because the number of nested functions can be very big.

Which technique can help us solve callback hell?

We can use promises that enable us to chain callbacks and deal with errosrs. Or otherwise we can use Fibers in Meteor.

1 Like