worker-timers
Advanced tools
Comparing version 4.0.29 to 4.0.30
@@ -54,6 +54,6 @@ { | ||
"sinon-chai": "^3.0.0", | ||
"ts-loader": "^4.1.0", | ||
"ts-loader": "^4.2.0", | ||
"tsconfig-holy-grail": "^4.0.5", | ||
"tslint": "^5.9.1", | ||
"tslint-config-holy-grail": "^23.0.12", | ||
"tslint-config-holy-grail": "^23.0.14", | ||
"typescript": "^2.8.1", | ||
@@ -93,3 +93,3 @@ "webpack": "^4.5.0" | ||
"types": "build/es2015/module.d.ts", | ||
"version": "4.0.29" | ||
"version": "4.0.30" | ||
} |
@@ -34,3 +34,5 @@ # worker-timers | ||
The usage is exactly the same as with the corresponding functions on the global scope. | ||
The usage is exactly the same (despite of the [error handling](#error-handling) and the | ||
[differentiation between intervals and timeouts](#differentiation-between-intervals-and-timeouts)) | ||
as with the corresponding functions on the global scope. | ||
@@ -51,2 +53,36 @@ ```js | ||
## Error Handling | ||
The native WindowTimers are very forgiving. Calling `clearInterval()` or `clearTimeout()` without | ||
a value or with an id which doesn't exist will just get ignored. In contrast to that workerTimers | ||
will throw an error when doing so. | ||
```js | ||
// This will just return undefined. | ||
window.clearTimeout('not-an-timeout-id'); | ||
// This will throw an error. | ||
workerTimers.clearTimeout('not-an-timeout-id'); | ||
``` | ||
## Differentiation between Intervals and Timeouts | ||
Another difference between workerTimers and WindowTimers is that this package maintains two | ||
separate lists to store the ids of intervals and timeouts internally. WindowTimers do only have one | ||
list which allows intervals to be cancelled by calling `clearTimeout()` and the other way round. | ||
This is not possible with workerTimers. As mentioned above workerTimers will throw an error when | ||
provided with an unknown id. | ||
```js | ||
const periodicWork = () => { }; | ||
// This will stop the interval. | ||
const windowId = window.setInterval(periodicWork, 100); | ||
window.clearTimeout(windowId); | ||
// This will throw an error. | ||
const workerId = workerTimers.setInterval(periodicWork, 100); | ||
workerTimers.clearTimeout(workerId); | ||
``` | ||
## Server-Side Rendering | ||
@@ -53,0 +89,0 @@ |
23912
108