10 examples of 'nodejs async queue' in JavaScript

Every line of 'nodejs async queue' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
588function asyncJS(js, fn) {
589 return new AsyncQueue(js, fn);
590}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

66async runQueue() {
67 // If it is empty, skip and keep the queue going
68 if (this.queue.isEmpty()) {
69 return setTimeout(this.runQueue.bind(this), this.queueTimeout);
70 }
71
72 // Get the command
73 const item = this.queue.dequeue();
74
75 this.logQueue(`Processing "${ item.command }" command from "${ item.from }"`);
76
77 // Handle the command accordingly
78 switch (item.from) {
79 case 'local':
80 if (!localCommandHandlers[item.command]) {
81 throw new Error(`Could not find handler for local:${ item.command }`);
82 }
83
84 await localCommandHandlers[item.command].apply(this, item.parameters);
85 break;
86 case 'peer':
87 if (!peerCommandHandlers[item.command]) {
88 throw new Error(`Could not find handler for peer:${ item.command }`);
89 }
90
91 await peerCommandHandlers[item.command].apply(this, item.parameters);
92 break;
93 }
94
95 // Keep the queue going
96 setTimeout(this.runQueue.bind(this), this.queueTimeout);
97}
287queue(queueName) {
288 return this._ironium.queue(queueName);
289}
55(function nextQueue(queueName) {
56 if (queueName) {
57 (function next(subscriber) {
58 if (subscriber) {
59 if (queue[queueName].strategy.removeSubscriber) {
60 queue[queueName].strategy.removeSubscriber(subscriber, function() {
61 next(queue[queueName].subscribers.pop());
62 });
63 } else {
64 next(queue[queueName].subscribers.pop());
65 }
66 } else {
67 nextQueue(queues.pop());
68 }
69 })(queue[queueName].subscribers.pop());
70 } else {
71 queue = {};
72 callback();
73 }
74})(queues.pop());
50add(func, toExec = true, ...args) {
51 const promise = new Promise( (resolve, reject) => {
52 const fn = this.createClosure(func, resolve, reject, ...args);
53 this._functions.push(fn);
54 } );
55
56 if (toExec && !this._running) {
57 this.exec();
58 }
59 return promise;
60}
30export function runNextInQueue(queueName: string) {
31 const queue = getPostbackQueue(queueName);
32 if (queue.queue.length > 0) {
33 const callback = queue.queue.shift()!;
34 window.setTimeout(callback, 0);
35 }
36}
9module.exports = function queueAddJob (q, job) {
10 logger('addJob', job)
11 return Promise.resolve().then(() => {
12 return jobParse.job(job)
13 }).map((oneJob) => {
14 if (oneJob.status === enums.status.created) {
15 oneJob.status = enums.status.waiting
16 }
17 const log = jobLog.createLogObject(oneJob,
18 null,
19 enums.message.jobAdded,
20 enums.log.information,
21 enums.status.waiting)
22 oneJob.log.push(log)
23 return oneJob.getCleanCopy()
24 }).then((cleanJobs) => {
25 logger(`cleanJobs`, cleanJobs)
26 return q.r.db(q.db)
27 .table(q.name)
28 .insert(cleanJobs, {returnChanges: true})
29 .run(q.queryRunOptions)
30 }).then((saveResult) => {
31 logger(`saveResult`, saveResult)
32 queueProcess.restart(q)
33 return dbResult.toJob(q, saveResult)
34 }).then((savedJobs) => {
35 for (let savedjob of savedJobs) {
36 logger(`Event: added [${savedjob.id}]`)
37 q.emit(enums.status.added, q.id, savedjob.id)
38 }
39 return savedJobs
40 })
41}
60function enqueue (queue, src, node, cb) {
61 console.log('Get src: ' + src + ', type: ' + node.type)
62 var job = {
63 src: src,
64 node: node
65 }
66 queue.push(job)
67 setTimeout(function () {
68 var n = queue.indexOf(job)
69 if (n !== -1) {
70 queue.splice(n, 1)
71 }
72 cb(null, srcData[src])
73 }, Math.random() * 10)
74}
57function queueWorker(task, queueCallback){
58 if(task.type == 'place'){
59 processPlace(task.json, queueCallback);
60 }
61 if(task.type == 'file'){
62 readFile(task.filename, queueCallback);
63 }
64};
44private runParallel(queue: Data[], data: Data[]): Promise<Data[]> {
45 return Promise.all(queue.map((fn: Data): Promise<Data> => fn(...data)));
46}

Related snippets