async-await-queue
Version:
async/await simple priority queues
912 lines (232 loc) • 9.83 kB
HTML
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Global</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Global</h1>
<section>
<header>
<h2></h2>
</header>
<article>
<div class="container-overview">
<dl class="details">
</dl>
</div>
<h3 class="subsection-title">Methods</h3>
<h4 class="name" id="end"><span class="type-signature"></span>end<span class="signature">(hash)</span><span class="type-signature"></span></h4>
<div class="description">
Signal that the task `hash` has finished.<br>
Frees its slot in the queue
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>hash</code></td>
<td class="type">
<span class="param-type">any</span>
</td>
<td class="description last">Unique hash identifying the task, Symbol() works very well</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line102">line 102</a>
</li></ul></dd>
</dl>
<h4 class="name" id="flush"><span class="type-signature"></span>flush<span class="signature">()</span><span class="type-signature"> → {Promise.<void>}</span></h4>
<div class="description">
Returns a promise that resolves when the queue is empty
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line182">line 182</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<void></span>
</dd>
</dl>
<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"> → {Promise.<any>}</span></h4>
<div class="description">
Run a job (equivalent to calling Queue.wait(), fn() and then Queue.end())<br>
fn can be both synchronous or asynchronous function
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>job</code></td>
<td class="type">
<span class="param-type">function</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">The job</td>
</tr>
<tr>
<td class="name"><code>priority</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">Optional priority, -1 is higher priority than 1</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line151">line 151</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Resolved when the task has finished with the return value of fn
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<any></span>
</dd>
</dl>
<h4 class="name" id="stat"><span class="type-signature"></span>stat<span class="signature">()</span><span class="type-signature"> → {QueueStats}</span></h4>
<div class="description">
Return the number of running and waiting jobs
</div>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line169">line 169</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
running, waiting, last
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">QueueStats</span>
</dd>
</dl>
<h4 class="name" id="wait"><span class="type-signature"></span>wait<span class="signature">(hash, priority<span class="signature-attributes">opt</span>)</span><span class="type-signature"> → {Promise.<void>}</span></h4>
<div class="description">
Wait for a slot in the queue
</div>
<h5>Parameters:</h5>
<table class="params">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Attributes</th>
<th>Default</th>
<th class="last">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td class="name"><code>hash</code></td>
<td class="type">
<span class="param-type">any</span>
</td>
<td class="attributes">
</td>
<td class="default">
</td>
<td class="description last">Unique hash identifying the task</td>
</tr>
<tr>
<td class="name"><code>priority</code></td>
<td class="type">
<span class="param-type">number</span>
</td>
<td class="attributes">
<optional><br>
</td>
<td class="default">
0
</td>
<td class="description last">Optional priority, -1 is higher priority than 1</td>
</tr>
</tbody>
</table>
<dl class="details">
<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="index.mjs.html">index.mjs</a>, <a href="index.mjs.html#line118">line 118</a>
</li></ul></dd>
</dl>
<h5>Returns:</h5>
<div class="param-desc">
Resolved when the task is ready to run
</div>
<dl>
<dt>
Type
</dt>
<dd>
<span class="param-type">Promise.<void></span>
</dd>
</dl>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><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.11</a> on Tue Jan 24 2023 19:53:17 GMT+0100 (Central European Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>