Introduction to Javascript Async Async Operations Library

Source: Internet
Author: User

Asynchronous Operations Knowledge

In the JS world, asynchronous operation is very popular, Nodejs is characterized by asynchronous non-blocking.

The asynchronous syntax supported by the JS language includes, Promise async await generator yield.

These grammars require the user to understand very clearly and often very difficult.

Here's a super-Library of asynchronous operations that can implement many asynchronous operations and process controls.

Async Library

Http://caolan.github.io/async/index.html

Async is a utility module which provides straight-forward, powerful functions for working with asynchronous JavaScript. Although originally designed for use with node. js and installable via npm install --save async , it can also be used directly in the browser.

Browser can also be used!!!

Async provides around functions that include the usual ' functional ' suspects ( map ,, reduce , filter each ...) as well as s ome common patterns for asynchronous control flow ( parallel , series , waterfall ...). All these functions assume you follow the node. JS Convention of providing a single callback as the last argument of your A Synchronous function--a callback which expects an Error as its first argument--and calling the callback once.

Includes 70 asynchronous functions, including the function type of the map reduce filter

and asynchronous control flow function parallel series

DEMO
Async.map ([' file1 ', ' file2 ', ' file3 '], Fs.stat,function(err, results) {//results is now a array of stats for each file}); Async.filter ([' File1 ', ' file2 ', ' file3 ',function(FilePath, callback) {fs.access (FilePath,function(Err) {Callback (NULL, !err)});function(err, results) {//results now equals an array of the existing files}); Async.Parallel ([function(callback) {...},function(callback) {...}],function(err, results) {//Optional Callback}); Async.series ([function(callback) {...},function(callback) {...}]);
parallel parallel execution, high efficiency. = = = Promise.all
The series is executed in a sequential order.
Race the execution of the race state. = = = Promise.race

Introduction to Javascript Async Async Operations Library

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.