/
legacy.js.html
112 lines (91 loc) · 3.69 KB
/
legacy.js.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: legacy.js</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">Source: legacy.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/**
* 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.
*/
import { clearIntervalAsync } from './clear'
import { validateHandler, validateInterval } from './validation'
import SetIntervalAsyncError from './error'
import SetIntervalAsyncTimer from './timer'
/**
* Executes the given handler at fixed intervals; ie. the start time<br>
* between consecutive executions is always a fixed amount of time.<br>
* If a given execution takes longer than the given time interval to<br>
* complete, then the handler will be invoked again without waiting<br>
* for the previous one to finish. In this scenario, multiple concurrent<br>
* executions can and will ocurr, so this function should only be used<br>
* when the given handler is reentrancy-safe.
*
* @param {function} handler - Handler function to be executed in intervals.<br>
* May be asynchronous.
* @param {number} interval - Interval in milliseconds. Must be at least 10 ms.
* @param {...*} args - Any number of arguments to pass on to the handler.
* @returns {SetIntervalAsyncTimer}
* A timer object which can be used to stop execution with {@link clearIntervalAsync}.
*
* @alias [Legacy] setIntervalAsync
*/
function setIntervalAsync (handler, interval, ...args) {
validateHandler(handler)
validateInterval(interval)
let timer = new SetIntervalAsyncTimer()
let id = timer.id
timer.timeouts[id] = setTimeout(
function timeoutHandler () {
let id = timer.id
if (!timer.stopped) {
timer.timeouts[id + 1] = setTimeout(timeoutHandler, interval)
}
timer.promises[id] = Promise.resolve(
).then(
() => {
return handler(...args)
}
).catch(
() => {}
).then(
() => {
delete timer.timeouts[id]
delete timer.promises[id]
}
)
timer.id = id + 1
},
interval
)
return timer
}
export { setIntervalAsync, clearIntervalAsync, SetIntervalAsyncError }
</code></pre>
</article>
</section>
</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>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed Jan 16 2019 19:52:39 GMT-0300 (Argentina Standard Time)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>