Gathering detailed insights and metrics for js-queue
Gathering detailed insights and metrics for js-queue
Gathering detailed insights and metrics for js-queue
Gathering detailed insights and metrics for js-queue
@node-ipc/js-queue
Simple JS queue with auto run for node and browsers
js-sdsl
javascript standard data structure library which benchmark against C++ STL
js-priority-queue
Priority queue data structures
heap-js
Efficient Binary heap (priority queue, binary tree) data structure for JavaScript / TypeScript. Includes JavaScript methods, Python's heapq module methods, and Java's PriorityQueue methods.
npm install js-queue
Typescript
Module System
Min. Node Version
Node Version
NPM Version
99.9
Supply Chain
99.4
Quality
75.7
Maintenance
100
Vulnerability
100
License
Easy stack update
Published on 11 Nov 2020
MIT Licence
Published on 11 Nov 2020
2.0.0
Published on 20 Dec 2016
added vanilla js version
Published on 23 Jun 2016
Production ready release and documentation
Published on 06 Jan 2016
better extendability and new features
Published on 04 Dec 2015
JavaScript (100%)
Total Downloads
185,950,978
Last Day
46,841
Last Week
403,037
Last Month
2,187,442
Last Year
25,092,049
48 Stars
26 Commits
6 Forks
4 Watching
1 Branches
2 Contributors
Latest Version
2.0.2
Package Id
js-queue@2.0.2
Size
4.13 kB
NPM Version
6.14.8
Node Version
14.11.0
Publised On
11 Nov 2020
Cumulative downloads
Total Downloads
Last day
-52.5%
46,841
Compared to previous day
Last week
-20.9%
403,037
Compared to previous week
Last month
-1.7%
2,187,442
Compared to previous month
Last year
-2.1%
25,092,049
Compared to previous year
1
Works great in node.js, webpack, browserify, or any other commonjs loader or compiler. To use in plain old vanilla browser javascript without common js just replace the requires in the examples with script tags. We show that below too.
js-queue
also exposes the easy-stack
stack via require('js-queue/stack.js')
this file exposes an ES6 stack which allows for Last In First Out (LIFO) queuing. This can come in handy depending on your application needs, check out the easy-stack javascript documentation it follows the js-queue
interface but is node 6 or greater as it uses ES6 classes.
npm install js-queue
npm info : See npm trends and stats for js-queue
GitHub info :
Package details websites :
This work is licenced via the MIT Licence.
key | type | paramaters | default | description |
---|---|---|---|---|
add | function | any number of functions | adds all parameter functions to queue and starts execution if autoRun is true, queue is not already running and queue is not forcibly stopped | |
next | function | executes next item in queue if queue is not forcibly stopped | ||
clear | function | removes remaining items in the queue | ||
contents | Array | Queue instance contents | ||
autoRun | Bool | true | should autoRun queue when new item added | |
stop | Bool | false | setting this to true will forcibly prevent the queue from executing |
1 2 var Queue=require('js-queue'); 3 //create a new queue instance 4 var queue=new Queue; 5 6 for(var i=0; i<50; i++){ 7 //add a bunch of stuff to the queue 8 queue.add(makeRequest); 9 } 10 11 function makeRequest(){ 12 //do stuff 13 console.log('making some request'); 14 15 this.next(); 16 } 17
The only difference is including via a script tag instead of using require.
1 2 <html> 3 <head> 4 <!-- this is the only difference --> 5 <script src='./queue-vanilla.js'></script> 6 <script> 7 console.log('my awesome app script'); 8 var queue=new Queue; 9 10 for(var i=0; i<50; i++){ 11 queue.add(makeRequest); 12 } 13 14 function makeRequest(){ 15 console.log('making some request'); 16 17 this.next(); 18 } 19 </script> 20 </head> 21 <body> 22 </body> 23 </html> 24
This allows you to start adding requests immediately and only execute if the websocket is connected. To use in plain browser based JS without webpack or browserify just replace the requires with the script tag.
1 2 var Queue=require('js-queue'); 3 4 //ws-share just makes it easier to share websocket code and ensure you don't open a websocket more than once 5 var WS=require('ws-share'); 6 7 //js-message makes it easy to create and parse normalized JSON messages. 8 var Message=require('js-message'); 9 10 //create a new queue instance 11 var queue=new Queue; 12 13 //force stop until websocket opened 14 queue.stop=true; 15 16 var ws=null; 17 18 function startWS(){ 19 //websocket.org rocks 20 ws=new WS('wss://echo.websocket.org/?encoding=text'); 21 22 ws.on( 23 'open', 24 function(){ 25 ws.on( 26 'message', 27 handleResponse 28 ); 29 30 //now that websocket is opened allow auto execution 31 queue.stop=false; 32 queue.next(); 33 } 34 ); 35 36 ws.on( 37 'error', 38 function(err){ 39 //stop execution of queue if there is an error because the websocket is likely closed 40 queue.stop=true; 41 //remove remaining items in the queue 42 queue.clear(); 43 throw(err); 44 } 45 ); 46 47 ws.on( 48 'close', 49 function(){ 50 //stop execution of queue when the websocket closed 51 queue.stop=true; 52 } 53 ); 54 } 55 56 //simulate a lot of requests being queued up for the websocket 57 for(var i=0; i<50; i++){ 58 queue.add(makeRequest); 59 } 60 61 var messageID=0; 62 63 function handleResponse(e){ 64 var message=new Message; 65 message.load(e.data); 66 67 console.log(message.type,message.data); 68 } 69 70 function makeRequest(){ 71 messageID++; 72 var message=new Message; 73 message.type='testMessage'; 74 message.data=messageID; 75 76 ws.send(message.JSON); 77 78 this.next(); 79 } 80 81 startWS(); 82
1 2 var Queue=require('js-queue'); 3 4 //MyAwesomeQueue inherits from Queue 5 MyAwesomeQueue.prototype = new Queue; 6 //Constructor will extend Queue 7 MyAwesomeQueue.prototype.constructor = MyAwesomeQueue; 8 9 function MyAwesomeQueue(){ 10 //extend with some stuff your app needs, 11 //maybe npm publish your extention with js-queue as a dependancy? 12 Object.defineProperties( 13 this, 14 { 15 isStopped:{ 16 enumerable:true, 17 get:checkStopped, 18 set:checkStopped 19 }, 20 removeThirdItem:{ 21 enumerable:true, 22 writable:false, 23 value:removeThird 24 } 25 } 26 ); 27 28 //enforce Object.assign for extending by locking down Class structure 29 //no willy nilly cowboy coding 30 Object.seal(this); 31 32 function checkStopped(){ 33 return this.stop; 34 } 35 36 function removeThird(){ 37 //get the queue content 38 var list=this.contents; 39 //modify the queue content 40 list.splice(2,1); 41 //save the modified queue content 42 this.contents=list; 43 44 return this.contents; 45 } 46 } 47
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/26 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-12-23
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 More