3131 < input type ="text " id ="nav-search " placeholder ="Search " />
3232
3333
34- < h2 > < a href ="index.html "> Home</ a > </ h2 > < h2 > < a href ="https://github.com/superbrobenji/async-queue " target ="_blank " class ="menu-item " id ="repository " > Github repo</ a > </ h2 > < h3 > Classes</ h3 > < ul > < li > < a href ="AsyncQueue.module.exports.html "> AsyncQueue.module.exports</ a > </ li > </ ul > < h3 > Namespaces</ h3 > < ul > < li > < a href ="AsyncQueue.html "> AsyncQueue</ a > < ul class ='methods '> < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.add "> add</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setMaxConcurrency "> setMaxConcurrency</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setPromiseTimeout "> setPromiseTimeout</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setRetries "> setRetries</ a > </ li > </ ul > </ li > </ ul > < h3 > Global</ h3 > < ul > < li > < a href ="global.html#promiseFunction "> promiseFunction</ a > </ li > < li > < a href ="global.html#returnCallback "> returnCallback</ a > </ li > </ ul >
34+ < h2 > < a href ="index.html "> Home</ a > </ h2 > < h2 > < a href ="https://github.com/superbrobenji/async-queue " target ="_blank " class ="menu-item " id ="repository " > Github repo</ a > </ h2 > < h3 > Classes</ h3 > < ul > < li > < a href ="AsyncQueue.module.exports.html "> AsyncQueue.module.exports</ a > </ li > </ ul > < h3 > Namespaces</ h3 > < ul > < li > < a href ="AsyncQueue.html "> AsyncQueue</ a > < ul class ='methods '> < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.add "> add</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setMaxConcurrency "> setMaxConcurrency</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setMaxRetries "> setMaxRetries</ a > </ li > < li data-type ='method ' style ='display: none; '> < a href ="AsyncQueue.html#.setPromiseTimeout "> setPromiseTimeout</ a > </ li > </ ul > </ li > </ ul > < h3 > Global</ h3 > < ul > < li > < a href ="global.html#abortHandler "> abortHandler</ a > </ li > < li > < a href ="global.html#errCallback "> errCallback</ a > </ li > < li > < a href ="global.html#promiseFunction "> promiseFunction</ a > </ li > < li > < a href ="global.html#resCallback "> resCallback</ a > </ li > </ ul >
3535
3636</ nav >
3737
@@ -80,7 +80,7 @@ <h4 class="name" id="AsyncQueue">AsyncQueue</h4>
8080
8181 < dt class ="tag-source "> Source:</ dt >
8282 < dd class ="tag-source "> < ul class ="dummy "> < li >
83- < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line2 "> line 2 </ a >
83+ < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line4 "> line 4 </ a >
8484 </ li > </ ul > </ dd >
8585
8686
@@ -177,7 +177,7 @@ <h3 class="subsection-title">Methods</h3>
177177
178178
179179
180- < h4 class ="name " id =".add "> < span class ="type-signature type-signature-static "> (static) </ span > add< span class ="signature "> (fn, callback)</ span > < span class ="type-signature "> </ span > </ h4 >
180+ < h4 class ="name " id =".add "> < span class ="type-signature type-signature-static "> (static) </ span > add< span class ="signature "> (fn, callback, callback )</ span > < span class ="type-signature "> </ span > </ h4 >
181181
182182
183183
@@ -194,7 +194,7 @@ <h4 class="name" id=".add"><span class="type-signature type-signature-static">(s
194194
195195 < dt class ="tag-source "> Source:</ dt >
196196 < dd class ="tag-source "> < ul class ="dummy "> < li >
197- < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line174 "> line 174 </ a >
197+ < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line230 "> line 230 </ a >
198198 </ li > </ ul > </ dd >
199199
200200
@@ -251,15 +251,16 @@ <h5 class="h5-examples">Example</h5>
251251}
252252
253253//the callback that is ran on the settlement of the promise
254- const callback = (res, err) => {
255- if(err){
256- throw new error(err)
257- }
254+ const callback = (res) => {
258255 //do something with response
259256}
260257
258+ const error = (err) => {
259+ throw new Error(err)
260+ }
261+
261262//Adding the promise to the queue
262- queue.add(pets, callback)</ code > </ pre >
263+ queue.add(pets, callback, error )</ code > </ pre >
263264
264265
265266
@@ -319,7 +320,31 @@ <h5 class="h5-parameters">Parameters:</h5>
319320 < td class ="type ">
320321
321322
322- < span class ="param-type "> < a href ="global.html#returnCallback "> returnCallback</ a > </ span >
323+ < span class ="param-type "> < a href ="global.html#resCallback "> resCallback</ a > </ span >
324+
325+
326+
327+
328+ </ td >
329+
330+
331+
332+
333+
334+ < td class ="description last "> < p > The function that is executed when the promise resolves</ p > </ td >
335+ </ tr >
336+
337+
338+
339+ < tr >
340+
341+ < td class ="name "> < code > callback</ code > </ td >
342+
343+
344+ < td class ="type ">
345+
346+
347+ < span class ="param-type "> < a href ="global.html#errCallback "> errCallback</ a > </ span >
323348
324349
325350
@@ -330,7 +355,7 @@ <h5 class="h5-parameters">Parameters:</h5>
330355
331356
332357
333- < td class ="description last "> < p > The function that is executed when the promise settles </ p > </ td >
358+ < td class ="description last "> < p > The function that is executed when the promise rejects </ p > </ td >
334359 </ tr >
335360
336361
@@ -376,7 +401,7 @@ <h4 class="name" id=".setMaxConcurrency"><span class="type-signature type-signat
376401
377402 < dt class ="tag-source "> Source:</ dt >
378403 < dd class ="tag-source "> < ul class ="dummy "> < li >
379- < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line40 "> line 40 </ a >
404+ < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line51 "> line 51 </ a >
380405 </ li > </ ul > </ dd >
381406
382407
@@ -495,7 +520,7 @@ <h5 class="h5-parameters">Parameters:</h5>
495520
496521
497522
498- < h4 class ="name " id =".setPromiseTimeout "> < span class ="type-signature type-signature-static "> (static) </ span > setPromiseTimeout < span class ="signature "> (timeout )</ span > < span class ="type-signature "> </ span > </ h4 >
523+ < h4 class ="name " id =".setMaxRetries "> < span class ="type-signature type-signature-static "> (static) </ span > setMaxRetries < span class ="signature "> (maxRetries )</ span > < span class ="type-signature "> </ span > </ h4 >
499524
500525
501526
@@ -505,14 +530,14 @@ <h4 class="name" id=".setPromiseTimeout"><span class="type-signature type-signat
505530< dl class ="details ">
506531
507532 < dt class ="tag-description "> Description:</ dt >
508- < dd class ="tag-description "> < ul class ="dummy "> < li > < p > Set the max amount of time a promise can take to settle
509- By default the queue will not monitor the promise time to settle </ p > </ li > </ ul > </ dd >
533+ < dd class ="tag-description "> < ul class ="dummy "> < li > < p > Set the max amount of times a promise can be retried after a failure
534+ By default the queue will not retry a failed promise. </ p > </ li > </ ul > </ dd >
510535
511536
512537
513538 < dt class ="tag-source "> Source:</ dt >
514539 < dd class ="tag-source "> < ul class ="dummy "> < li >
515- < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line103 "> line 103 </ a >
540+ < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line85 "> line 85 </ a >
516541 </ li > </ ul > </ dd >
517542
518543
@@ -544,13 +569,6 @@ <h4 class="name" id=".setPromiseTimeout"><span class="type-signature type-signat
544569
545570
546571
547-
548- < dt class ="tag-todo "> To Do:</ dt >
549- < dd class ="tag-todo ">
550- < ul >
551- < li > implement abort controller to kill promise when timeout is reached</ li >
552- </ ul >
553- </ dd >
554572
555573</ dl >
556574
@@ -568,23 +586,25 @@ <h5 class="h5-examples">Example</h5>
568586
569587 < pre class ="prettyprint "> < code > const queue = new Queue()
570588
571- //setting timeout for promises to 100ms
572- queue.setPromiseTimeout(100 )
589+ //setting retries to 3
590+ queue.setRetries(3 )
573591
574- //function returns the promise we want to add to queue
575592const pets = () => {
576- return new Promise((resolve) => {
577- setTimeout(resolve, 500) //note that the timeout in the promise is larger than the set promise timeout
593+ return new Promise((resolve, reject ) => {
594+ setTimeout(reject('rejected'), 100)
578595 })
579596}
580597
581- //the callback that is ran on the settlement of the promise
582- const callback = (res, err) => {
583- console.log(err) //output: "Request timed out"
598+ const callback = (res) => {
599+ //do something with data
584600}
585601
586- //Adding the promise to the queue
587- queue.add(pets, callback)</ code > </ pre >
602+ const errCallback = ( err) => {
603+ console.log(err.message) // output: 'max retries reached'
604+ console.log(err.errors) // output: list of errors
605+ }
606+
607+ queue.add(pets, callback, errCallback)</ code > </ pre >
588608
589609
590610
@@ -614,7 +634,7 @@ <h5 class="h5-parameters">Parameters:</h5>
614634
615635 < tr >
616636
617- < td class ="name "> < code > timeout </ code > </ td >
637+ < td class ="name "> < code > maxRetries </ code > </ td >
618638
619639
620640 < td class ="type ">
@@ -631,7 +651,7 @@ <h5 class="h5-parameters">Parameters:</h5>
631651
632652
633653
634- < td class ="description last "> < p > The max amount of time in ms a promise can take to settle </ p > </ td >
654+ < td class ="description last "> < p > The max amount of promises to run concurrently </ p > </ td >
635655 </ tr >
636656
637657
@@ -661,7 +681,7 @@ <h5 class="h5-parameters">Parameters:</h5>
661681
662682
663683
664- < h4 class ="name " id =".setRetries "> < span class ="type-signature type-signature-static "> (static) </ span > setRetries < span class ="signature "> (maxRetries )</ span > < span class ="type-signature "> </ span > </ h4 >
684+ < h4 class ="name " id =".setPromiseTimeout "> < span class ="type-signature type-signature-static "> (static) </ span > setPromiseTimeout < span class ="signature "> (timeout )</ span > < span class ="type-signature "> </ span > </ h4 >
665685
666686
667687
@@ -671,14 +691,15 @@ <h4 class="name" id=".setRetries"><span class="type-signature type-signature-sta
671691< dl class ="details ">
672692
673693 < dt class ="tag-description "> Description:</ dt >
674- < dd class ="tag-description "> < ul class ="dummy "> < li > < p > Set the max amount of times a promise can be retried after a failure
675- By default the queue will not retry a failed promise.</ p > </ li > </ ul > </ dd >
694+ < dd class ="tag-description "> < ul class ="dummy "> < li > < p > Set the max amount of time a promise can take to settle
695+ By default the queue will not monitor the promise time to settle
696+ a signal must be handled in the promise for the timeout to abort the promise</ p > </ li > </ ul > </ dd >
676697
677698
678699
679700 < dt class ="tag-source "> Source:</ dt >
680701 < dd class ="tag-source "> < ul class ="dummy "> < li >
681- < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line70 "> line 70 </ a >
702+ < a href ="index.js.html "> index.js</ a > , < a href ="index.js.html#line131 "> line 131 </ a >
682703 </ li > </ ul > </ dd >
683704
684705
@@ -710,6 +731,13 @@ <h4 class="name" id=".setRetries"><span class="type-signature type-signature-sta
710731
711732
712733
734+
735+ < dt class ="tag-todo "> To Do:</ dt >
736+ < dd class ="tag-todo ">
737+ < ul >
738+ < li > implement abort controller to kill promise when timeout is reached</ li >
739+ </ ul >
740+ </ dd >
713741
714742</ dl >
715743
@@ -727,21 +755,31 @@ <h5 class="h5-examples">Example</h5>
727755
728756 < pre class ="prettyprint "> < code > const queue = new Queue()
729757
730- //setting retries to 3
731- queue.setRetries(3 )
758+ //setting timeout for promises to 100ms
759+ queue.setPromiseTimeout(100 )
732760
733- const pets = () => {
761+ //function returns the promise we want to add to queue
762+ const pets = (signal) => {
734763 return new Promise((resolve, reject) => {
735- setTimeout(reject('rejected'), 100)
764+ signal.addEventListener("abort", () => {
765+ reject("Aborted")
766+ }
767+ setTimeout(resolve, 500) //note that the timeout in the promise is larger than the set promise timeout
736768 })
737769}
738770
739- const callback = (res, err) => {
740- console.log(err.message) // output: 'max retries reached'
741- console.log(err.cause) // output: ['rejected', 'rejected', 'rejected']
771+ //the callback that is ran on the resolution of the promise
772+ const callback = (res ) => {
773+ //do something with data
774+ }
775+
776+ //the callback that is ran on the rejection of the promise
777+ const errCallback = (err) => {
778+ console.log(err) //output: "Request timed out"
742779}
743780
744- queue.add(pets, callback)</ code > </ pre >
781+ //Adding the promise to the queue
782+ queue.add(pets, callback, errCallback)</ code > </ pre >
745783
746784
747785
@@ -771,7 +809,7 @@ <h5 class="h5-parameters">Parameters:</h5>
771809
772810 < tr >
773811
774- < td class ="name "> < code > maxRetries </ code > </ td >
812+ < td class ="name "> < code > timeout </ code > </ td >
775813
776814
777815 < td class ="type ">
@@ -788,7 +826,7 @@ <h5 class="h5-parameters">Parameters:</h5>
788826
789827
790828
791- < td class ="description last "> < p > The max amount of promises to run concurrently </ p > </ td >
829+ < td class ="description last "> < p > The max amount of time in ms a promise can take to settle </ p > </ td >
792830 </ tr >
793831
794832
@@ -833,7 +871,7 @@ <h5 class="h5-parameters">Parameters:</h5>
833871< br class ="clear ">
834872
835873< footer >
836- Documentation generated by < a href ="https://github.com/jsdoc3/jsdoc "> JSDoc 4.0.4</ a > on Thu Nov 14 2024 23:29:04 GMT+0200 (South Africa Standard Time) using the < a href ="https://github.com/clenemt/docdash "> docdash</ a > theme.
874+ Documentation generated by < a href ="https://github.com/jsdoc3/jsdoc "> JSDoc 4.0.4</ a > on Tue Nov 26 2024 17:05:18 GMT+0200 (South Africa Standard Time) using the < a href ="https://github.com/clenemt/docdash "> docdash</ a > theme.
837875</ footer >
838876
839877< script > prettyPrint ( ) ; </ script >
0 commit comments