Skip to content

Commit 8b08f93

Browse files
Merge pull request #66 from superbrobenji/bug/abort-on-timeout
added abort on timeout
2 parents 0c14a6c + a4929c0 commit 8b08f93

File tree

11 files changed

+637
-308
lines changed

11 files changed

+637
-308
lines changed

docs/jsdoc/AsyncQueue.html

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
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#.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#errCallback">errCallback</a></li><li><a href="global.html#promiseFunction">promiseFunction</a></li><li><a href="global.html#resCallback">resCallback</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#line5">line 5</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

@@ -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#line226">line 226</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

@@ -401,7 +401,7 @@ <h4 class="name" id=".setMaxConcurrency"><span class="type-signature type-signat
401401

402402
<dt class="tag-source">Source:</dt>
403403
<dd class="tag-source"><ul class="dummy"><li>
404-
<a href="index.js.html">index.js</a>, <a href="index.js.html#line55">line 55</a>
404+
<a href="index.js.html">index.js</a>, <a href="index.js.html#line51">line 51</a>
405405
</li></ul></dd>
406406

407407

@@ -537,7 +537,7 @@ <h4 class="name" id=".setMaxRetries"><span class="type-signature type-signature-
537537

538538
<dt class="tag-source">Source:</dt>
539539
<dd class="tag-source"><ul class="dummy"><li>
540-
<a href="index.js.html">index.js</a>, <a href="index.js.html#line89">line 89</a>
540+
<a href="index.js.html">index.js</a>, <a href="index.js.html#line85">line 85</a>
541541
</li></ul></dd>
542542

543543

@@ -601,7 +601,7 @@ <h5 class="h5-examples">Example</h5>
601601

602602
const errCallback = ( err) => {
603603
console.log(err.message) // output: 'max retries reached'
604-
console.log(err.cause) // output: ['rejected', 'rejected', 'rejected']
604+
console.log(err.errors) // output: list of errors
605605
}
606606

607607
queue.add(pets, callback, errCallback)</code></pre>
@@ -692,7 +692,8 @@ <h4 class="name" id=".setPromiseTimeout"><span class="type-signature type-signat
692692

693693
<dt class="tag-description">Description:</dt>
694694
<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</p></li></ul></dd>
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>
696697

697698

698699

@@ -758,8 +759,11 @@ <h5 class="h5-examples">Example</h5>
758759
queue.setPromiseTimeout(100)
759760

760761
//function returns the promise we want to add to queue
761-
const pets = () =>{
762-
return new Promise((resolve) =>{
762+
const pets = (signal) =>{
763+
return new Promise((resolve, reject) =>{
764+
signal.addEventListener("abort", () => {
765+
reject("Aborted")
766+
}
763767
setTimeout(resolve, 500) //note that the timeout in the promise is larger than the set promise timeout
764768
})
765769
}
@@ -867,7 +871,7 @@ <h5 class="h5-parameters">Parameters:</h5>
867871
<br class="clear">
868872

869873
<footer>
870-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Tue Nov 26 2024 12:40:27 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.
871875
</footer>
872876

873877
<script>prettyPrint();</script>

docs/jsdoc/AsyncQueue.module.exports.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
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#.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#errCallback">errCallback</a></li><li><a href="global.html#promiseFunction">promiseFunction</a></li><li><a href="global.html#resCallback">resCallback</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

@@ -68,7 +68,7 @@ <h2>
6868

6969

7070

71-
<h4 class="name" id="module.exports"><span class="type-signature"></span>new module.exports<span class="signature">(maxConcurrency<span class="signature-attributes">opt</span>, maxRetries, timeout)</span><span class="type-signature"></span></h4>
71+
<h4 class="name" id="module.exports"><span class="type-signature"></span>new module.exports<span class="signature">(maxConcurrency<span class="signature-attributes">opt</span>, maxRetries<span class="signature-attributes">opt</span>, timeout<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4>
7272

7373

7474

@@ -84,7 +84,7 @@ <h4 class="name" id="module.exports"><span class="type-signature"></span>new mod
8484

8585
<dt class="tag-source">Source:</dt>
8686
<dd class="tag-source"><ul class="dummy"><li>
87-
<a href="index.js.html">index.js</a>, <a href="index.js.html#line38">line 38</a>
87+
<a href="index.js.html">index.js</a>, <a href="index.js.html#line34">line 34</a>
8888
</li></ul></dd>
8989

9090

@@ -217,6 +217,8 @@ <h5 class="h5-parameters">Parameters:</h5>
217217

218218
<td class="attributes">
219219

220+
&lt;optional><br>
221+
220222

221223

222224

@@ -249,6 +251,8 @@ <h5 class="h5-parameters">Parameters:</h5>
249251

250252
<td class="attributes">
251253

254+
&lt;optional><br>
255+
252256

253257

254258

@@ -320,7 +324,7 @@ <h5 class="h5-parameters">Parameters:</h5>
320324
<br class="clear">
321325

322326
<footer>
323-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Tue Nov 26 2024 12:40:27 GMT+0200 (South Africa Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
327+
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.
324328
</footer>
325329

326330
<script>prettyPrint();</script>

docs/jsdoc/global.html

Lines changed: 162 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
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#.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#errCallback">errCallback</a></li><li><a href="global.html#promiseFunction">promiseFunction</a></li><li><a href="global.html#resCallback">resCallback</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

@@ -123,6 +123,97 @@ <h2>
123123

124124

125125

126+
<h3 class="subsection-title">Members</h3>
127+
128+
129+
130+
<h4 class="name" id="abortHandler"><span class="type-signature type-signature-constant">(constant) </span>abortHandler<span class="type-signature"></span></h4>
131+
132+
133+
134+
135+
136+
<dl class="details">
137+
138+
<dt class="tag-description">Description:</dt>
139+
<dd class="tag-description"><ul class="dummy"><li><p>abort handler for handling aborts in your promise</p></li></ul></dd>
140+
141+
142+
143+
<dt class="tag-source">Source:</dt>
144+
<dd class="tag-source"><ul class="dummy"><li>
145+
<a href="index.js.html">index.js</a>, <a href="index.js.html#line303">line 303</a>
146+
</li></ul></dd>
147+
148+
149+
150+
151+
152+
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
163+
164+
165+
166+
167+
168+
169+
170+
171+
172+
173+
174+
175+
176+
177+
178+
</dl>
179+
180+
181+
182+
183+
184+
<div class="description usertext">
185+
<p>abort handler for handling aborts in your promise</p>
186+
</div>
187+
188+
189+
190+
191+
192+
193+
194+
<h5 class="h5-examples">Example</h5>
195+
196+
<pre class="prettyprint"><code>const promise = (signal) => {
197+
return new Promise((resolve, reject) => {
198+
abortHandler(signal, reject);
199+
200+
setTimeout(resolve, 5000, "resolved");
201+
});
202+
};
203+
204+
const callback = (res) {
205+
// handle res here
206+
}
207+
const errHandler = (err) {
208+
console.log(err.message) //output: "Aborted"
209+
}
210+
211+
queue.add(promise, callback, errHandler)</code></pre>
212+
213+
214+
215+
216+
126217

127218

128219

@@ -311,7 +402,7 @@ <h5 class="h5-returns">Returns:</h5>
311402

312403

313404

314-
<h4 class="name" id="promiseFunction"><span class="type-signature"></span>promiseFunction<span class="signature">()</span><span class="type-signature"> &rarr; {Promise.&lt;any>}</span></h4>
405+
<h4 class="name" id="promiseFunction"><span class="type-signature"></span>promiseFunction<span class="signature">(signal<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;unknown>}</span></h4>
315406

316407

317408

@@ -371,15 +462,80 @@ <h4 class="name" id="promiseFunction"><span class="type-signature"></span>promis
371462

372463
<h5 class="h5-examples">Example</h5>
373464

374-
<pre class="prettyprint"><code>const pets = () =>{
375-
return new Promise((resolve) =>{
465+
<pre class="prettyprint"><code>const pets = (signal) =>{
466+
return new Promise((resolve, reject) =>{
467+
signal.addEventListener("abort", () => {
468+
reject("Aborted")
469+
}
376470
setTimeout(resolve, 100)
377471
})
378472
}</code></pre>
379473

380474

381475

382476

477+
<h5 class="h5-parameters">Parameters:</h5>
478+
479+
480+
<table class="params">
481+
<thead>
482+
<tr>
483+
484+
<th>Name</th>
485+
486+
487+
<th>Type</th>
488+
489+
490+
<th>Attributes</th>
491+
492+
493+
494+
495+
<th class="last">Description</th>
496+
</tr>
497+
</thead>
498+
499+
<tbody>
500+
501+
502+
<tr>
503+
504+
<td class="name"><code>signal</code></td>
505+
506+
507+
<td class="type">
508+
509+
510+
<span class="param-type">AbortSignal</span>
511+
512+
513+
514+
515+
</td>
516+
517+
518+
<td class="attributes">
519+
520+
&lt;optional><br>
521+
522+
523+
524+
525+
526+
</td>
527+
528+
529+
530+
531+
<td class="description last"><p>The signal for the abort controller for the timeout to abort the promise</p></td>
532+
</tr>
533+
534+
535+
</tbody>
536+
</table>
537+
538+
383539

384540

385541

@@ -409,7 +565,7 @@ <h5 class="h5-returns">Returns:</h5>
409565
</dt>
410566
<dd>
411567

412-
<span class="param-type">Promise.&lt;any></span>
568+
<span class="param-type">Promise.&lt;unknown></span>
413569

414570

415571

@@ -611,7 +767,7 @@ <h5 class="h5-returns">Returns:</h5>
611767
<br class="clear">
612768

613769
<footer>
614-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Tue Nov 26 2024 12:40:27 GMT+0200 (South Africa Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
770+
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.
615771
</footer>
616772

617773
<script>prettyPrint();</script>

docs/jsdoc/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
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#.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#errCallback">errCallback</a></li><li><a href="global.html#promiseFunction">promiseFunction</a></li><li><a href="global.html#resCallback">resCallback</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

@@ -127,7 +127,7 @@ <h2>📝 License</h2>
127127
<br class="clear">
128128

129129
<footer>
130-
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.4</a> on Tue Nov 26 2024 12:40:27 GMT+0200 (South Africa Standard Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
130+
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.
131131
</footer>
132132

133133
<script>prettyPrint();</script>

0 commit comments

Comments
 (0)