Skip to content

Commit

Permalink
v1.0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
ealmansi committed Jan 17, 2019
1 parent 899e102 commit 3214fd9
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 103 deletions.
4 changes: 2 additions & 2 deletions docs/SetIntervalAsyncError.html
Expand Up @@ -153,13 +153,13 @@ <h4 class="name" id="SetIntervalAsyncError"><span class="type-signature"></span>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/SetIntervalAsyncTimer.html
Expand Up @@ -154,13 +154,13 @@ <h4 class="name" id="SetIntervalAsyncTimer"><span class="type-signature"></span>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
20 changes: 11 additions & 9 deletions docs/clear.js.html
Expand Up @@ -32,6 +32,8 @@ <h1 class="page-title">Source: clear.js</h1>
* For a copy, see the file LICENSE in the root directory.
*/

let MAX_INTERVAL_MS = Math.pow(2, 31) - 1

/**
* Stops an execution cycle started by setIntervalAsync.&lt;br>
* Any ongoing function executions will run until completion,
Expand All @@ -46,17 +48,17 @@ <h1 class="page-title">Source: clear.js</h1>
for (let timeout of Object.values(timer.timeouts)) {
clearTimeout(timeout)
}
let noop = () => {}
let promises = Object
.values(timer.promises)
.map(
(promise) => promise.catch(() => {})
(promise) => {
promise.catch(noop)
}
)
let intervalId = setInterval(() => {}, Math.pow(2, 31) - 1)
await Promise.all(
promises
).then(
() => clearInterval(intervalId)
)
let noopInterval = setInterval(noop, MAX_INTERVAL_MS)
await Promise.all(promises)
clearInterval(noopInterval)
}

export { clearIntervalAsync }
Expand All @@ -70,13 +72,13 @@ <h1 class="page-title">Source: clear.js</h1>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
68 changes: 38 additions & 30 deletions docs/dynamic.js.html
Expand Up @@ -59,38 +59,46 @@ <h1 class="page-title">Source: dynamic.js</h1>
let timer = new SetIntervalAsyncTimer()
let id = timer.id
timer.timeouts[id] = setTimeout(
function timeoutHandler () {
let id = timer.id
let startTime = null; let endTime = null
timer.promises[id] = Promise.resolve(
).then(
() => {
startTime = new Date()
return handler(...args)
}
).catch(
(err) => {
console.error(err)
}
).then(
() => {
endTime = new Date()
delete timer.timeouts[id]
delete timer.promises[id]
if (!timer.stopped) {
let executionTime = endTime - startTime
let timeout = interval > executionTime ? interval - executionTime : 0
timer.timeouts[id + 1] = setTimeout(timeoutHandler, timeout)
}
}
)
timer.id = id + 1
},
interval
timeoutHandler,
interval,
timer,
handler,
interval,
...args
)
return timer
}

function timeoutHandler (timer, handler, interval, ...args) {
let id = timer.id
timer.promises[id] = (async () => {
let startTime = new Date()
try {
await handler(...args)
} catch (err) {
console.error(err)
}
let endTime = new Date()
if (!timer.stopped) {
let executionTime = endTime - startTime
let timeout = interval > executionTime
? interval - executionTime
: 0
timer.timeouts[id + 1] = setTimeout(
timeoutHandler,
timeout,
timer,
handler,
interval,
...args
)
}
delete timer.timeouts[id]
delete timer.promises[id]
})()
timer.id = id + 1
}

export { setIntervalAsync, clearIntervalAsync, SetIntervalAsyncError }
</code></pre>
</article>
Expand All @@ -102,13 +110,13 @@ <h1 class="page-title">Source: dynamic.js</h1>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/error.js.html
Expand Up @@ -57,13 +57,13 @@ <h1 class="page-title">Source: error.js</h1>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
57 changes: 32 additions & 25 deletions docs/fixed.js.html
Expand Up @@ -59,33 +59,40 @@ <h1 class="page-title">Source: fixed.js</h1>
let timer = new SetIntervalAsyncTimer()
let id = timer.id
timer.timeouts[id] = setTimeout(
function timeoutHandler () {
let id = timer.id
timer.promises[id] = Promise.resolve(
).then(
() => {
return handler(...args)
}
).catch(
(err) => {
console.error(err)
}
).then(
() => {
delete timer.timeouts[id]
delete timer.promises[id]
if (!timer.stopped) {
timer.timeouts[id + 1] = setTimeout(timeoutHandler, interval)
}
}
)
timer.id = id + 1
},
interval
timeoutHandler,
interval,
timer,
handler,
interval,
...args
)
return timer
}

function timeoutHandler (timer, handler, interval, ...args) {
let id = timer.id
timer.promises[id] = (async () => {
try {
await handler(...args)
} catch (err) {
console.error(err)
}
if (!timer.stopped) {
timer.timeouts[id + 1] = setTimeout(
timeoutHandler,
interval,
timer,
handler,
interval,
...args
)
}
delete timer.timeouts[id]
delete timer.promises[id]
})()
timer.id = id + 1
}

export { setIntervalAsync, clearIntervalAsync, SetIntervalAsyncError }
</code></pre>
</article>
Expand All @@ -97,13 +104,13 @@ <h1 class="page-title">Source: fixed.js</h1>
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
74 changes: 71 additions & 3 deletions docs/global.html
Expand Up @@ -94,6 +94,74 @@ <h2></h2>



<h3 class="subsection-title">Members</h3>



<h4 class="name" id="MAX_INTERVAL_MS"><span class="type-signature"></span>MAX_INTERVAL_MS<span class="type-signature"></span></h4>




<div class="description">
Copyright (c) 2019 Emilio Almansi. All rights reserved.
This work is licensed under the terms of the MIT license.
For a copy, see the file LICENSE in the root directory.
</div>







<dl class="details">


























<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="clear.js.html">clear.js</a>, <a href="clear.js.html#line7">line 7</a>
</li></ul></dd>







</dl>










<h3 class="subsection-title">Methods</h3>
Expand Down Expand Up @@ -917,7 +985,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="clear.js.html">clear.js</a>, <a href="clear.js.html#line16">line 16</a>
<a href="clear.js.html">clear.js</a>, <a href="clear.js.html#line18">line 18</a>
</li></ul></dd>


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

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Expand Up @@ -177,13 +177,13 @@ <h1>Contributing</h1><p>In order to contribute to this project, you will need to
</div>

<nav>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li></ul>
<h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="SetIntervalAsyncError.html">SetIntervalAsyncError</a></li><li><a href="SetIntervalAsyncTimer.html">SetIntervalAsyncTimer</a></li></ul><h3>Global</h3><ul><li><a href="global.html#%255BDynamic%255DsetIntervalAsync">[Dynamic] setIntervalAsync</a></li><li><a href="global.html#%255BFixed%255DsetIntervalAsync">[Fixed] setIntervalAsync</a></li><li><a href="global.html#%255BLegacy%255DsetIntervalAsync">[Legacy] setIntervalAsync</a></li><li><a href="global.html#clearIntervalAsync">clearIntervalAsync</a></li><li><a href="global.html#MAX_INTERVAL_MS">MAX_INTERVAL_MS</a></li></ul>
</nav>

<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 01:00:13 GMT-0300 (Argentina Standard Time)
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Thu Jan 17 2019 12:27:38 GMT-0300 (Argentina Standard Time)
</footer>

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

0 comments on commit 3214fd9

Please sign in to comment.