Installations
npm install async-lite
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
0.12.0
NPM Version
2.5.1
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
SamDelgado
Download Statistics
Total Downloads
6,057
Last Day
2
Last Week
8
Last Month
51
Last Year
1,271
GitHub Statistics
3 Stars
12 Commits
2 Forks
1 Watching
1 Branches
1 Contributors
Bundle Size
1.60 kB
Minified
743.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.0.3
Package Id
async-lite@1.0.3
Size
5.76 kB
NPM Version
2.5.1
Node Version
0.12.0
Total Downloads
Cumulative downloads
Total Downloads
6,057
Last day
100%
2
Compared to previous day
Last week
-63.6%
8
Compared to previous week
Last month
-40.7%
51
Compared to previous month
Last year
139.8%
1,271
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
5
Async-Lite.js
Async-Lite is a tiny async library (1kb minified) for modern environments with no dependencies, and only containing each, eachSeries, series, and parallel methods. These methods are the ones I most often use when I need asynchronous looping or control flow, so bringing in the entire caolan/async library was overkill. You can use with Node.js or in the browser. Install it via npm install async-lite
or just grab the async-lite.min.js file from this repository.
Documentation
each(arr, iterator, [callback])
Loop through an array without caring what order your array items are accessed. If any item passes an error to its callback, no other items are processed, and the main callback is immediately called with the value of the error.
1 2var async = require('async-lite'); 3 4var myArray = [{name: "Sam", timeToWait: 200}, {name: "Bill", timeToWait: 400}, {name: "Steve", timeToWait: 600}]; 5 6function someAsyncFunction(item, callback) { 7 8 setTimeout(function() { 9 10 if (item.name === "Sam") { 11 alert("That is a great name"); 12 } else { 13 alert("You should change your name"); 14 } 15 16 callback(null); // leave the callback empty or callback null if there are no errors 17 18 }, item.timeToWait); 19 20} 21 22async.each(myArray, function(item, callback) { 23 24 someAsyncFunction(item, function(err) { 25 26 // callback when done 27 // passing in a truthy error will stop the whole loop 28 callback(err); 29 30 }); 31 32}); 33
The total time that passed could be as little as 600 milliseconds since all items are accessed at once. The total amount of time should be slightly longer than the slowest operation.
eachSeries(arr, iterator, [callback])
Loop through an array in order. An item will be only be accessed once the previous item is done being accessed. If any item passes an error to its callback, no other items are processed, and the main callback is immediately called with the value of the error.
1 2var async = require('async-lite'); 3 4var myArray = [{name: "Sam", timeToWait: 200}, {name: "Bill", timeToWait: 400}, {name: "Steve", timeToWait: 600}]; 5 6function someAsyncFunction(item, callback) { 7 8 setTimeout(function() { 9 10 if (item.name === "Sam") { 11 alert("That is a great name"); 12 } else { 13 alert("You should change your name"); 14 } 15 16 callback(null); // leave the callback empty or callback null if there are no errors 17 18 }, item.timeToWait); 19 20} 21 22async.eachSeries(myArray, function(item, callback) { 23 24 someAsyncFunction(item, function(err) { 25 26 // callback when done 27 // passing in a truthy error will stop the whole loop 28 callback(err); 29 30 }); 31 32}); 33
The total time that passed will be at least 1200 milliseconds since Bill had to wait 200 milliseconds for Sam to be done before starting, and then Steve had to wait 400 milliseconds for Bill to be done before starting.
series(tasks, [callback])
Run each of the tasks in the array, each one running once the previous task has completed. The callback will receive an array of results in the correct order once all tasks are completed. If any task passes an error to its callback, no other tasks are run, and the main callback is immediately called with the value of the error.
1 2var async = require('async-lite'); 3 4async.series([ 5 6 function task1(callback) { 7 setTimeout(function() { 8 callback(null, "task1"); 9 }, 600); 10 }, 11 12 function task2(callback) { 13 setTimeout(function() { 14 callback(null, "task2"); 15 }, 400); 16 }, 17 18 function task3(callback) { 19 setTimeout(function() { 20 callback(null, "task3"); 21 }, 200); 22 } 23 24], function(err, results) { 25 26 // results = ["task1", "task2", "task3"]; 27 28}); 29
The total time that passed will be at least 1200 milliseconds since task2 had to wait 600 milliseconds for task1 to be done before starting, and then task3 had to wait 400 milliseconds for task2 to be done before starting.
parallel(tasks, [callback])
Run all of the tasks simultaneously. Unlike the series method, parallel can accept an array or object. The callback will receive an array or object of results in the correct order once all tasks are completed. If any task passes an error to its callback, no other tasks are run, and the main callback is immediately called with the value of the error.
1 2var async = require('async-lite'); 3 4async.parallel([ 5 6 function task1(callback) { 7 setTimeout(function() { 8 callback(null, "task1"); 9 }, 600); 10 }, 11 12 function task2(callback) { 13 setTimeout(function() { 14 callback(null, "task2"); 15 }, 400); 16 }, 17 18 function task3(callback) { 19 setTimeout(function() { 20 callback(null, "task3"); 21 }, 200); 22 } 23 24], function(err, results) { 25 26 // results = ["task1", "task2", "task3"]; 27 28}); 29 30/*********** OR *************/ 31 32async.parallel({ 33 34 one: function(callback) { 35 setTimeout(function() { 36 callback(null, "task1"); 37 }, 600); 38 }, 39 40 two: function(callback) { 41 setTimeout(function() { 42 callback(null, "task2"); 43 }, 400); 44 }, 45 46 three: function(callback) { 47 setTimeout(function() { 48 callback(null, "task3"); 49 }, 200); 50 } 51 52}, function(err, results) { 53 54 // results = {one: "task1", two: "task2", three: "task3"}; 55 56}); 57
The total time that passed could be as little as 600 milliseconds since all tasks are processed at once. The total amount of time should be slightly longer than the slowest task.
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/12 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to async-lite
@types/rx-lite-async
TypeScript definitions for rx-lite-async
rx-lite-async
Lightweight library with asynchronous functions for composing asynchronous and event-based operations in JavaScript
rx-lite-async-compat
Lightweight older browser compatible library with asynchronous functions for composing asynchronous and event-based operations in JavaScript
websocket-promise-lite
WebSockets with a promise-based API (async/await). Lite, fast, easy.