worker-timers-broker
Advanced tools
Comparing version 7.0.0 to 7.0.1
export const isClearResponse = (message) => { | ||
return message.error === null && typeof message.id === 'number'; | ||
return typeof message.id === 'number' && typeof message.result === 'boolean'; | ||
}; | ||
//# sourceMappingURL=clear-response.js.map |
@@ -15,2 +15,5 @@ import { generateUniqueNumber } from 'fast-unique-numbers'; | ||
const idOrFunc = scheduledIntervalFunctions.get(timerId); | ||
if (typeof idOrFunc === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof idOrFunc === 'number') { | ||
@@ -24,11 +27,11 @@ const timerIdAndTimerType = unrespondedRequests.get(idOrFunc); | ||
} | ||
else if (typeof idOrFunc !== 'undefined') { | ||
else if (typeof idOrFunc === 'function') { | ||
idOrFunc(); | ||
} | ||
else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
} | ||
else if (timerType === 'timeout') { | ||
const idOrFunc = scheduledTimeoutFunctions.get(timerId); | ||
if (typeof idOrFunc === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof idOrFunc === 'number') { | ||
@@ -42,3 +45,3 @@ const timerIdAndTimerType = unrespondedRequests.get(idOrFunc); | ||
} | ||
else if (typeof idOrFunc !== 'undefined') { | ||
else if (typeof idOrFunc === 'function') { | ||
idOrFunc(); | ||
@@ -48,5 +51,2 @@ // A timeout can be savely deleted because it is only called once. | ||
} | ||
else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
} | ||
@@ -75,26 +75,24 @@ } | ||
const clearInterval = (timerId) => { | ||
if (typeof scheduledIntervalFunctions.get(timerId) !== 'function') { | ||
throw new Error(`There is no interval scheduled with the given id "${timerId}".`); | ||
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') { | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'interval' }); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'interval' } | ||
}); | ||
} | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'interval' }); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'interval' } | ||
}); | ||
}; | ||
const clearTimeout = (timerId) => { | ||
if (typeof scheduledTimeoutFunctions.get(timerId) !== 'function') { | ||
throw new Error(`There is no timeout scheduled with the given id "${timerId}".`); | ||
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') { | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'timeout' }); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'timeout' } | ||
}); | ||
} | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'timeout' }); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'timeout' } | ||
}); | ||
}; | ||
@@ -112,3 +110,3 @@ const setInterval = (func, delay = 0) => { | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -125,3 +123,3 @@ timerType: 'interval' | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -141,3 +139,3 @@ timerType: 'interval' | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -144,0 +142,0 @@ timerType: 'timeout' |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fast-unique-numbers')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'fast-unique-numbers'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workerTimersBroker = {}, global.fastUniqueNumbers)); | ||
})(this, (function (exports, fastUniqueNumbers) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@babel/runtime/helpers/typeof'), require('fast-unique-numbers')) : | ||
typeof define === 'function' && define.amd ? define(['exports', '@babel/runtime/helpers/typeof', 'fast-unique-numbers'], factory) : | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.workerTimersBroker = {}, global._typeof, global.fastUniqueNumbers)); | ||
})(this, (function (exports, _typeof, fastUniqueNumbers) { 'use strict'; | ||
@@ -12,3 +12,3 @@ var isCallNotification = function isCallNotification(message) { | ||
var isClearResponse = function isClearResponse(message) { | ||
return message.error === null && typeof message.id === 'number'; | ||
return typeof message.id === 'number' && typeof message.result === 'boolean'; | ||
}; | ||
@@ -30,2 +30,5 @@ | ||
var idOrFunc = scheduledIntervalFunctions.get(timerId); | ||
if (_typeof(idOrFunc) === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof idOrFunc === 'number') { | ||
@@ -36,9 +39,10 @@ var timerIdAndTimerType = unrespondedRequests.get(idOrFunc); | ||
} | ||
} else if (typeof idOrFunc !== 'undefined') { | ||
} else if (typeof idOrFunc === 'function') { | ||
idOrFunc(); | ||
} else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
} else if (timerType === 'timeout') { | ||
var _idOrFunc = scheduledTimeoutFunctions.get(timerId); | ||
if (_typeof(_idOrFunc) === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof _idOrFunc === 'number') { | ||
@@ -49,8 +53,6 @@ var _timerIdAndTimerType = unrespondedRequests.get(_idOrFunc); | ||
} | ||
} else if (typeof _idOrFunc !== 'undefined') { | ||
} else if (typeof _idOrFunc === 'function') { | ||
_idOrFunc(); | ||
// A timeout can be savely deleted because it is only called once. | ||
scheduledTimeoutFunctions["delete"](timerId); | ||
} else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
@@ -78,38 +80,36 @@ } | ||
var clearInterval = function clearInterval(timerId) { | ||
if (typeof scheduledIntervalFunctions.get(timerId) !== 'function') { | ||
throw new Error("There is no interval scheduled with the given id \"".concat(timerId, "\".")); | ||
} | ||
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { | ||
timerId: timerId, | ||
timerType: 'interval' | ||
}); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id: id, | ||
method: 'clear', | ||
params: { | ||
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') { | ||
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { | ||
timerId: timerId, | ||
timerType: 'interval' | ||
} | ||
}); | ||
}); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id: id, | ||
method: 'clear', | ||
params: { | ||
timerId: timerId, | ||
timerType: 'interval' | ||
} | ||
}); | ||
} | ||
}; | ||
var clearTimeout = function clearTimeout(timerId) { | ||
if (typeof scheduledTimeoutFunctions.get(timerId) !== 'function') { | ||
throw new Error("There is no timeout scheduled with the given id \"".concat(timerId, "\".")); | ||
} | ||
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { | ||
timerId: timerId, | ||
timerType: 'timeout' | ||
}); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id: id, | ||
method: 'clear', | ||
params: { | ||
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') { | ||
var id = fastUniqueNumbers.generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { | ||
timerId: timerId, | ||
timerType: 'timeout' | ||
} | ||
}); | ||
}); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
worker.postMessage({ | ||
id: id, | ||
method: 'clear', | ||
params: { | ||
timerId: timerId, | ||
timerType: 'timeout' | ||
} | ||
}); | ||
} | ||
}; | ||
@@ -128,3 +128,3 @@ var setInterval = function setInterval(func) { | ||
delay: delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId: timerId, | ||
@@ -141,3 +141,3 @@ timerType: 'interval' | ||
delay: delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId: timerId, | ||
@@ -158,3 +158,3 @@ timerType: 'interval' | ||
delay: delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId: timerId, | ||
@@ -161,0 +161,0 @@ timerType: 'timeout' |
@@ -15,3 +15,3 @@ { | ||
"tslib": "^2.6.2", | ||
"worker-timers-worker": "^7.0.71" | ||
"worker-timers-worker": "^8.0.0" | ||
}, | ||
@@ -44,3 +44,3 @@ "description": "The broker which is used by the worker-timers package.", | ||
"karma-webpack": "^5.0.1", | ||
"lint-staged": "^15.2.2", | ||
"lint-staged": "^15.2.4", | ||
"load-grunt-config": "^4.0.1", | ||
@@ -85,3 +85,3 @@ "mocha": "^10.4.0", | ||
"types": "build/es2019/module.d.ts", | ||
"version": "7.0.0" | ||
"version": "7.0.1" | ||
} |
import { IClearResponse, TWorkerMessage } from 'worker-timers-worker'; | ||
export const isClearResponse = (message: TWorkerMessage): message is IClearResponse => { | ||
return (<IClearResponse>message).error === null && typeof message.id === 'number'; | ||
return typeof message.id === 'number' && typeof (<IClearResponse>message).result === 'boolean'; | ||
}; |
@@ -23,2 +23,6 @@ import { generateUniqueNumber } from 'fast-unique-numbers'; | ||
if (typeof idOrFunc === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof idOrFunc === 'number') { | ||
@@ -34,6 +38,4 @@ const timerIdAndTimerType = unrespondedRequests.get(idOrFunc); | ||
} | ||
} else if (typeof idOrFunc !== 'undefined') { | ||
} else if (typeof idOrFunc === 'function') { | ||
idOrFunc(); | ||
} else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
@@ -43,2 +45,6 @@ } else if (timerType === 'timeout') { | ||
if (typeof idOrFunc === undefined) { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
if (typeof idOrFunc === 'number') { | ||
@@ -54,3 +60,3 @@ const timerIdAndTimerType = unrespondedRequests.get(idOrFunc); | ||
} | ||
} else if (typeof idOrFunc !== 'undefined') { | ||
} else if (typeof idOrFunc === 'function') { | ||
idOrFunc(); | ||
@@ -60,4 +66,2 @@ | ||
scheduledTimeoutFunctions.delete(timerId); | ||
} else { | ||
throw new Error('The timer is in an undefined state.'); | ||
} | ||
@@ -93,33 +97,29 @@ } | ||
const clearInterval = (timerId: number) => { | ||
if (typeof scheduledIntervalFunctions.get(timerId) !== 'function') { | ||
throw new Error(`There is no interval scheduled with the given id "${timerId}".`); | ||
} | ||
if (typeof scheduledIntervalFunctions.get(timerId) === 'function') { | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'interval' }); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
unrespondedRequests.set(id, { timerId, timerType: 'interval' }); | ||
scheduledIntervalFunctions.set(timerId, id); | ||
worker.postMessage(<IClearRequest>{ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'interval' } | ||
}); | ||
worker.postMessage(<IClearRequest>{ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'interval' } | ||
}); | ||
} | ||
}; | ||
const clearTimeout = (timerId: number) => { | ||
if (typeof scheduledTimeoutFunctions.get(timerId) !== 'function') { | ||
throw new Error(`There is no timeout scheduled with the given id "${timerId}".`); | ||
} | ||
if (typeof scheduledTimeoutFunctions.get(timerId) === 'function') { | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
const id = generateUniqueNumber(unrespondedRequests); | ||
unrespondedRequests.set(id, { timerId, timerType: 'timeout' }); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
unrespondedRequests.set(id, { timerId, timerType: 'timeout' }); | ||
scheduledTimeoutFunctions.set(timerId, id); | ||
worker.postMessage(<IClearRequest>{ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'timeout' } | ||
}); | ||
worker.postMessage(<IClearRequest>{ | ||
id, | ||
method: 'clear', | ||
params: { timerId, timerType: 'timeout' } | ||
}); | ||
} | ||
}; | ||
@@ -140,3 +140,3 @@ | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -154,3 +154,3 @@ timerType: 'interval' | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -174,3 +174,3 @@ timerType: 'interval' | ||
delay, | ||
now: performance.now(), | ||
now: performance.timeOrigin + performance.now(), | ||
timerId, | ||
@@ -177,0 +177,0 @@ timerType: 'timeout' |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
31577
486
+ Addedworker-timers-worker@8.0.0(transitive)
- Removedworker-timers-worker@7.0.71(transitive)
Updatedworker-timers-worker@^8.0.0