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