Skip to content

Commit

Permalink
regen the doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Jan 24, 2023
1 parent 6dcdc7e commit e4e5f0c
Show file tree
Hide file tree
Showing 7 changed files with 314 additions and 164 deletions.
20 changes: 20 additions & 0 deletions .jsdoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"plugins": [],
"recurseDepth": 10,
"source": {
"includePattern": ".+\\.mjs$",
"excludePattern": "(^|\\/|\\\\)_"
},
"sourceType": "module",
"tags": {
"allowUnknownTags": true,
"dictionaries": [
"jsdoc",
"closure"
]
},
"templates": {
"cleverLinks": false,
"monospaceLinks": false
}
}
6 changes: 3 additions & 3 deletions docs/QueueStats.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ <h2>QueueStats</h2>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line115">line 115</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line169">line 169</a>
</li></ul></dd>


Expand Down Expand Up @@ -115,13 +115,13 @@ <h2>QueueStats</h2>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports_module.exports.html">exports</a></li></ul><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Apr 05 2022 14:45:49 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Tue Jan 24 2023 19:51:53 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
18 changes: 9 additions & 9 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line39">line 39</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line102">line 102</a>
</li></ul></dd>


Expand Down Expand Up @@ -294,7 +294,7 @@ <h4 class="name" id="flush"><span class="type-signature"></span>flush<span class

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line133">line 133</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line185">line 185</a>
</li></ul></dd>


Expand Down Expand Up @@ -348,7 +348,7 @@ <h5>Returns:</h5>



<h4 class="name" id="run"><span class="type-signature"></span>run<span class="signature">(fn, priority<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;any>}</span></h4>
<h4 class="name" id="run"><span class="type-signature"></span>run<span class="signature">(job, priority<span class="signature-attributes">opt</span>)</span><span class="type-signature"> &rarr; {Promise.&lt;any>}</span></h4>



Expand Down Expand Up @@ -397,7 +397,7 @@ <h5>Parameters:</h5>

<tr>

<td class="name"><code>fn</code></td>
<td class="name"><code>job</code></td>


<td class="type">
Expand Down Expand Up @@ -505,7 +505,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line96">line 96</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line151">line 151</a>
</li></ul></dd>


Expand Down Expand Up @@ -615,7 +615,7 @@ <h4 class="name" id="stat"><span class="type-signature"></span>stat<span class="

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line119">line 119</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line172">line 172</a>
</li></ul></dd>


Expand Down Expand Up @@ -829,7 +829,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="queue.js.html">queue.js</a>, <a href="queue.js.html#line57">line 57</a>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line118">line 118</a>
</li></ul></dd>


Expand Down Expand Up @@ -897,13 +897,13 @@ <h5>Returns:</h5>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports_module.exports.html">exports</a></li></ul><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Apr 05 2022 14:45:49 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Tue Jan 24 2023 19:51:53 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
148 changes: 2 additions & 146 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,150 +42,6 @@ <h3> </h3>



<section>
<article><h1>async/await-compatible Promise-based priority queues</h1>
<p><a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="https://github.com/mmomtchev/Queue/actions?query=workflow%3A%22Node.js+CI%22"><img src="https://github.com/mmomtchev/Queue/workflows/Node.js%20CI/badge.svg" alt="Node.js CI"></a>
<a href="https://codecov.io/gh/mmomtchev/Queue"><img src="https://codecov.io/gh/mmomtchev/Queue/branch/master/graph/badge.svg" alt="codecov"></a></p>
<p>1726 bytes and <em><strong>zero-dependency</strong></em> if you are not rebuilding the minified versions yourself.</p>
<p>There is a medium story about using this package to parallelize download loops : <a href="https://medium.com/@mmomtchev/parallelizing-download-loops-in-js-with-async-await-queue-670420880cd6">Parallelizing download loops in JS with async-await-queue</a></p>
<p>This is an interesting solution to the priority queues problem.</p>
<p>There are other Promise-based queues out there but they are not async/await compatible and do not support priorities.</p>
<p>It guarantees order and never wakes up contexts that won't run.</p>
<p>I use it with tens of thousands of jobs on the queue. <em>O(1)</em> on the number of jobs, <em>O(n)</em> on the number of different priorities, so be reasonable. Just make sure to awalys call <code>Queue.end()</code>. Or, since 1.2, there is a safer, but less versatile method, <code>Queue.run()</code>.</p>
<p>These can be used to rate-limit expensive external API requests.</p>
<p>The queues keep references to the Promise <code>resolve()</code> function and resolve it from outside of the Promise constructor.
This is a very unusual use of Promises to implement locks that I find interesting.
The language specification doesn't make it clear if this is allowed or not, but it seems to work very well.
It works both in the browser and in Node.js.</p>
<h1>Install</h1>
<p><code>npm install --save async-await-queue</code></p>
<h1>Typical usage</h1>
<p>Require as <strong>CJS/UMD</strong></p>
<pre class="prettyprint source lang-js"><code>const Queue = require('async-await-queue');
</code></pre>
<p>Import as <strong>ES Module</strong></p>
<pre class="prettyprint source lang-js"><code>import Queue from 'async-await-queue';
</code></pre>
<p>(or read the <a href="https://mmomtchev.github.io/Queue/">jsdoc</a>)</p>
<p><em><strong>IMPORTANT</strong></em> Keep in mind that when running asynchronous code without explicitly <code>await</code>ing it, you should always handle the eventual Promise rejections by a <code>.catch()</code> statement.</p>
<pre class="prettyprint source lang-js"><code>const Queue = require('async-await-queue');
/* No more than 2 concurrent tasks with
* at least 100ms between two tasks
*/
const myq = new Queue(2, 100);

....

const myPriority = -1;


/* This function will launch all tasks and will
* wait for them to be scheduled, returning
* only when all tasks have finished
*/
async function downloadTheInternet() {
for (let site of Internet) {
/* The third call will wait for the previous two to complete
* plus the time needed to make this at least 100ms
* after the second call
* The first argument needs to be unique for every
* task on the queue
*/
const me = Symbol();
/* We wait in the line here */
await myq.wait(me, myPriority);

/* Do your expensive async task here
* Queue will schedule it at
* no more than 2 parallel running requests
* launched at least 100ms apart
*/
download(site)
/* Signal that we are finished */
/* Do not forget to handle the exceptions! */
.catch((e) => console.error(e))
.finally(() => myq.end(me));
}
return await myq.flush();
}

/* This is the new style API introduced in 1.2
* It is equivalent to the last example
*/
async function downloadTheInternet() {
const q = [];
for (let site of Internet) {
/* The third call will wait for the previous two to complete
* plus the time needed to make this at least 100ms
* after the second call
*/
q.push(myq.run(() =>
download(site)
.catch((e) => console.error(e))
);
}
return Promise.all(q);
}


/* This function will execute a single task at a time
* waiting for its place in the queue
*/
async function downloadTheInternet() {
let p;
/* The third call will wait for the previous two to complete
* plus the time needed to make this at least 100ms
* after the second call
* The first argument needs to be unique for every
* task on the queue
*/
const me = Symbol();
/* We wait in the line here */
await myq.wait(me, myPriority);

/* Do your expensive async task here
* Queue will schedule it at
* no more than 2 parallel running requests
* launched at least 100ms apart
*/
try {
await download(site);
} catch (e) {
console.error(e);
} finally {
/* Signal that we are finished */
/* Do not forget to handle the exceptions! */
myq.end(me);
}
}


/* This function will schedule all the taks and
* then will return immediately a single Promise
* that can be awaited upon
*/
async function downloadTheInternet() {
const q = [];
for (let site of Internet) {
/* The third call will wait for the previous two to complete
* plus the time needed to make this at least 100ms
* after the second call
* The first argument needs to be unique for every
* task on the queue
*/
const me = Symbol();
q.push(myq.wait(me, myPriority)
.then(() => download(site))
.catch((e) => console.error(e))
.finally(() => myq.end(me)));
}
return Promise.all(q);
}

</code></pre></article>
</section>




Expand All @@ -194,13 +50,13 @@ <h1>Typical usage</h1>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="module.exports_module.exports.html">exports</a></li></ul><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Interfaces</h3><ul><li><a href="QueueStats.html">QueueStats</a></li></ul><h3>Global</h3><ul><li><a href="global.html#end">end</a></li><li><a href="global.html#flush">flush</a></li><li><a href="global.html#run">run</a></li><li><a href="global.html#stat">stat</a></li><li><a href="global.html#wait">wait</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.7</a> on Tue Apr 05 2022 14:45:49 GMT+0200 (Central European Summer Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.11</a> on Tue Jan 24 2023 19:51:53 GMT+0100 (Central European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit e4e5f0c

Please sign in to comment.