Angular 8 Tutorial

Angular 8 Introduction History and versions of Angular 8 Architecture of Angular 8 How to install Angular 8 and set-up it. Creating our first Angular 8 app Angular 8 app loading

Difference between Angular And react

Angular vs react

Angular 8 Advantages Disadvantage

Advantage and Disadvantage of Angular 8

Angular 8 file structure

Angular 8 file structure

Angular 8 components

Components of Angular 8

Angular 8 CLI Commands

All CLI commands of Angular

Angular 8 with Bootstrap

How to install bootstrap for Angular 8 Libraries of Angular 8

Angular 8 Routing

Routing in Angular 8

Angular 8 directives

Angular 8 Directives Angular 8 ngIf directive Angular 8 ngFor directive Angular 8 ngSwitch directive Angular 8 ngClass directive Angular 8 ngStyle directive

Angular 8 pipes

Angular 8 Pipes

Angular 8 databinding

Angular 8 Data binding Angular 8 Event binding Angular 8 Property binding Two-way data binding in Angular 8

String Interpolation In Angular 8

Angular 8 String interpolation

Angular 8 forms

Angular 8 Forms Data flow of forms in Angular 8 Creating forms in Angular 8 Testing and validation of forms in Angular 8

Error fixing in Angular 8

Error fixing in Angular 8

Dependency injection and services in Angular 8

Dependency injection services in Angular 8

Angular 8 Animations

Angular 8 Animations

Dynamic components in Angular 8

Dynamic components in Angular 8

Angular 8 Module

Angular 8 Module Deploying an angular 8 app

Introduction of unit testing in angular 8

Unit testing in angular 8

Observables in angular 8

Observables in angular 8

Angular 8 universal

Angular 8 universal

Angular 8 Changes and new features

New features and changes in Angular 8

Conclusion

Angular 8 Conclusion

Node.js async.queue() Method

Node.js async.queue() Method

What is Async module?

In Node.js, we have an async module that has a lot of functionality, but the main use case of this module is to do multiple processes at a continuous time.

To execute multiple tasks at once, this method uses a queue. A queue is a data structure which works in the order of First In First Out, which means whatever element is added first to the queue will be executed first although we can change the order of elements according to our priority.

To use the async module in our file, first, we have to install it using npm(Node Package Manager).

Syntax:

npm install async

After installing, we will have to import this module into our file.

Syntax:

const async=require('async');

As we know, we always use the require keyword to import any module in our file in Node.js. Now, the next step is to initialize the queue where we will execute our tasks.

Syntax:

Const queue=async.queue('fxn', 'concurrency_val');

If you notice the above syntax, then we see that async.queue() method accepts two arguments.

The first one is a function and the second one is the concurrency value.

Fxn is the function which will be executed upon the elements which have been added to the queue by the user. Concurrency value is an integer argument which means the number of tasks executing at a time.

For example:

// Defining The queue
const que = async.queue((element, completed) => {	
	console.log("Currently running task is the task number " + element);
		setTimeout(()=>{
		const remaining_task = queue.length();
		completed(null, {element, remaining_task});
	}, 2000);


}, 1);

Explanation:

In the above code, we use the concurrency value as 1, which means we will process one task at a time.

In the function, we defined that on each element, we will print the element which is under process, and then we will call the timeout function after 2000 milliseconds or 2 seconds. We use the remaining_task variable to store the remaining task in the queue, which is going to be executed next.

We have a lot of functions which can be used on our async queue.

1. length() method

This method returns an integer variable which describes the number of elements present in the queue.

So, with this function, we can determine the number of remaining tasks.

Syntax:

qu.length();

2. push() method

The push method takes two arguments: the first one is the element or task which we want to add to the queue, and the other one is a callback function which will be executed when we process that task.

One thing to notice is that in the push method, tasks are added to the end of the queue.

Syntax:

qu.push(task, (err, {task, remaining}) => {
if(err){
	console.log(`there is an error  in the task ${task}`);
} else {
	console.log(`queue has execute the task ${task}
			. ${remaining} tasks remaining`);
}
});

Started attribute

This attribute returns a Boolean value. If the queue has started the execution of tasks, then it will return true else, it will return false.

Syntax:

qu.started;

3. unshift() method

It is exactly the same as the push method, but the key difference is that it adds the task in front of the queue instead of ending. We use this function if we want to execute some important tasks first.

Syntax:

qu.unshift(task, (err, {task, remaining}) => {
if(err){
	console.log(`there is an error  in the task ${task}`);
} else {
	console.log(`queue has execute the task ${task}
			. ${remaining} tasks remaining`);
}
});

4. drain() method

This method basically runs a callback function which will be executed when we have zero elements in the queue or all the tasks have been completed.

Syntax:

qu.drain();

5. pause() method

This function will pause the execution of tasks in the queue.

Syntax:

qu.pause();

6. resume() method

This function will start the execution of tasks if execution is paused using the pause() method.

Syntax:

qu.resume();

7. kill() method

This function will remove the tasks from the queue, and it will not run the drain() method also.

Basically, it will put the queue into the idle condition where no task is executed.

Syntax:

qu.kill();

8. idle() method

This function will return a boolean value. If the queue is not doing any task, then it will return true else, it will return false.

Syntax:

qu.idle();