worker-timers-worker
Advanced tools
Comparing version 2.0.2 to 3.0.0
@@ -1,4 +0,4 @@ | ||
export declare const clearScheduledInterval: (id: number) => void; | ||
export declare const clearScheduledTimeout: (id: number) => void; | ||
export declare const scheduleInterval: (delay: number, id: number, nowInMainThread: number) => void; | ||
export declare const scheduleTimeout: (delay: number, id: number, nowInMainThread: number) => void; | ||
export declare const clearScheduledInterval: (timerId: number) => void; | ||
export declare const clearScheduledTimeout: (timerId: number) => void; | ||
export declare const scheduleInterval: (delay: number, timerId: number, nowInMainThread: number) => void; | ||
export declare const scheduleTimeout: (delay: number, timerId: number, nowInMainThread: number) => void; |
const scheduledIntervalIdentifiers = new Map(); | ||
const scheduledTimeoutIdentifiers = new Map(); | ||
export const clearScheduledInterval = (id) => { | ||
const identifier = scheduledIntervalIdentifiers.get(id); | ||
export const clearScheduledInterval = (timerId) => { | ||
const identifier = scheduledIntervalIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledIntervalIdentifiers.delete(id); | ||
scheduledIntervalIdentifiers.delete(timerId); | ||
} | ||
else { | ||
throw new Error(`There is no interval scheduled with the given id "${id}".`); | ||
throw new Error(`There is no interval scheduled with the given id "${timerId}".`); | ||
} | ||
}; | ||
export const clearScheduledTimeout = (id) => { | ||
const identifier = scheduledTimeoutIdentifiers.get(id); | ||
export const clearScheduledTimeout = (timerId) => { | ||
const identifier = scheduledTimeoutIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledTimeoutIdentifiers.delete(id); | ||
scheduledTimeoutIdentifiers.delete(timerId); | ||
} | ||
else { | ||
throw new Error(`There is no timeout scheduled with the given id "${id}".`); | ||
throw new Error(`There is no timeout scheduled with the given id "${timerId}".`); | ||
} | ||
@@ -37,21 +37,21 @@ }; | ||
}; | ||
const setTimeoutCallback = (identifiers, id, expected, type) => { | ||
const setTimeoutCallback = (identifiers, timerId, expected, timerType) => { | ||
const now = ('performance' in self) ? performance.now() : Date.now(); | ||
if (now > expected) { | ||
postMessage({ id, type }); | ||
postMessage({ method: 'call', params: { timerId, timerType } }); | ||
} | ||
else { | ||
identifiers.set(id, setTimeout(setTimeoutCallback, (expected - now), identifiers, id, expected, type)); | ||
identifiers.set(timerId, setTimeout(setTimeoutCallback, (expected - now), identifiers, timerId, expected, timerType)); | ||
} | ||
}; | ||
export const scheduleInterval = (delay, id, nowInMainThread) => { | ||
export const scheduleInterval = (delay, timerId, nowInMainThread) => { | ||
let expected; | ||
({ delay, expected } = computeDelayAndExpectedCallbackTime(delay, nowInMainThread)); | ||
scheduledIntervalIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, id, expected, 'interval')); | ||
scheduledIntervalIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, timerId, expected, 'interval')); | ||
}; | ||
export const scheduleTimeout = (delay, id, nowInMainThread) => { | ||
export const scheduleTimeout = (delay, timerId, nowInMainThread) => { | ||
let expected; | ||
({ delay, expected } = computeDelayAndExpectedCallbackTime(delay, nowInMainThread)); | ||
scheduledTimeoutIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, id, expected, 'timeout')); | ||
scheduledTimeoutIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, timerId, expected, 'timeout')); | ||
}; | ||
//# sourceMappingURL=/users/chrisguttandin/repositories/worker-timers-worker/node_modules/tsconfig-holy-grail/src/helpers/timer.js.map |
@@ -1,2 +0,2 @@ | ||
import { IWorkerTimersEvent } from './interfaces/worker-timers-event'; | ||
export { IWorkerTimersEvent }; | ||
export * from './interfaces'; | ||
export * from './types'; |
import { clearScheduledInterval, clearScheduledTimeout, scheduleInterval, scheduleTimeout } from './helpers/timer'; | ||
addEventListener('message', ({ data: { action, delay, id, now, type } }) => { | ||
addEventListener('message', ({ data }) => { | ||
try { | ||
if (action === 'clear') { | ||
if (type === 'interval') { | ||
clearScheduledInterval(id); | ||
if (data.method === 'clear') { | ||
const { id, params: { timerId, timerType } } = data; | ||
if (timerType === 'interval') { | ||
clearScheduledInterval(timerId); | ||
postMessage({ id }); | ||
} | ||
else if (type === 'timeout') { | ||
clearScheduledTimeout(id); | ||
else if (timerType === 'timeout') { | ||
clearScheduledTimeout(timerId); | ||
postMessage({ id }); | ||
} | ||
else { | ||
throw new Error(`The given type "${type}" is not supported`); | ||
throw new Error(`The given type "${timerType}" is not supported`); | ||
} | ||
} | ||
else if (action === 'set') { | ||
if (type === 'interval') { | ||
scheduleInterval(delay, id, now); | ||
else if (data.method === 'set') { | ||
const { params: { delay, now, timerId, timerType } } = data; | ||
if (timerType === 'interval') { | ||
scheduleInterval(delay, timerId, now); | ||
} | ||
else if (type === 'timeout') { | ||
scheduleTimeout(delay, id, now); | ||
else if (timerType === 'timeout') { | ||
scheduleTimeout(delay, timerId, now); | ||
} | ||
else { | ||
throw new Error(`The given type "${type}" is not supported`); | ||
throw new Error(`The given type "${timerType}" is not supported`); | ||
} | ||
} | ||
else { | ||
throw new Error(`The given action "${action}" is not supported`); | ||
throw new Error(`The given method "${data.method}" is not supported`); | ||
} | ||
@@ -29,0 +33,0 @@ } |
@@ -6,18 +6,18 @@ (function () { | ||
var scheduledTimeoutIdentifiers = new Map(); | ||
var clearScheduledInterval = function clearScheduledInterval(id) { | ||
var identifier = scheduledIntervalIdentifiers.get(id); | ||
var clearScheduledInterval = function clearScheduledInterval(timerId) { | ||
var identifier = scheduledIntervalIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledIntervalIdentifiers.delete(id); | ||
scheduledIntervalIdentifiers.delete(timerId); | ||
} else { | ||
throw new Error('There is no interval scheduled with the given id "' + id + '".'); | ||
throw new Error('There is no interval scheduled with the given id "' + timerId + '".'); | ||
} | ||
}; | ||
var clearScheduledTimeout = function clearScheduledTimeout(id) { | ||
var identifier = scheduledTimeoutIdentifiers.get(id); | ||
var clearScheduledTimeout = function clearScheduledTimeout(timerId) { | ||
var identifier = scheduledTimeoutIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledTimeoutIdentifiers.delete(id); | ||
scheduledTimeoutIdentifiers.delete(timerId); | ||
} else { | ||
throw new Error('There is no timeout scheduled with the given id "' + id + '".'); | ||
throw new Error('There is no timeout scheduled with the given id "' + timerId + '".'); | ||
} | ||
@@ -38,11 +38,11 @@ }; | ||
}; | ||
var setTimeoutCallback = function setTimeoutCallback(identifiers, id, expected, type) { | ||
var setTimeoutCallback = function setTimeoutCallback(identifiers, timerId, expected, timerType) { | ||
var now = 'performance' in self ? performance.now() : Date.now(); | ||
if (now > expected) { | ||
postMessage({ id: id, type: type }); | ||
postMessage({ method: 'call', params: { timerId: timerId, timerType: timerType } }); | ||
} else { | ||
identifiers.set(id, setTimeout(setTimeoutCallback, expected - now, identifiers, id, expected, type)); | ||
identifiers.set(timerId, setTimeout(setTimeoutCallback, expected - now, identifiers, timerId, expected, timerType)); | ||
} | ||
}; | ||
var scheduleInterval = function scheduleInterval(delay, id, nowInMainThread) { | ||
var scheduleInterval = function scheduleInterval(delay, timerId, nowInMainThread) { | ||
var expected = void 0; | ||
@@ -55,5 +55,5 @@ | ||
scheduledIntervalIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, id, expected, 'interval')); | ||
scheduledIntervalIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, timerId, expected, 'interval')); | ||
}; | ||
var scheduleTimeout = function scheduleTimeout(delay, id, nowInMainThread) { | ||
var scheduleTimeout = function scheduleTimeout(delay, timerId, nowInMainThread) { | ||
var expected = void 0; | ||
@@ -66,32 +66,40 @@ | ||
scheduledTimeoutIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, id, expected, 'timeout')); | ||
scheduledTimeoutIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, timerId, expected, 'timeout')); | ||
}; | ||
addEventListener('message', function (_ref) { | ||
var _ref$data = _ref.data, | ||
action = _ref$data.action, | ||
delay = _ref$data.delay, | ||
id = _ref$data.id, | ||
now = _ref$data.now, | ||
type = _ref$data.type; | ||
var data = _ref.data; | ||
try { | ||
if (action === 'clear') { | ||
if (type === 'interval') { | ||
clearScheduledInterval(id); | ||
} else if (type === 'timeout') { | ||
clearScheduledTimeout(id); | ||
if (data.method === 'clear') { | ||
var id = data.id, | ||
_data$params = data.params, | ||
timerId = _data$params.timerId, | ||
timerType = _data$params.timerType; | ||
if (timerType === 'interval') { | ||
clearScheduledInterval(timerId); | ||
postMessage({ id: id }); | ||
} else if (timerType === 'timeout') { | ||
clearScheduledTimeout(timerId); | ||
postMessage({ id: id }); | ||
} else { | ||
throw new Error('The given type "' + type + '" is not supported'); | ||
throw new Error('The given type "' + timerType + '" is not supported'); | ||
} | ||
} else if (action === 'set') { | ||
if (type === 'interval') { | ||
scheduleInterval(delay, id, now); | ||
} else if (type === 'timeout') { | ||
scheduleTimeout(delay, id, now); | ||
} else if (data.method === 'set') { | ||
var _data$params2 = data.params, | ||
delay = _data$params2.delay, | ||
now = _data$params2.now, | ||
_timerId = _data$params2.timerId, | ||
_timerType = _data$params2.timerType; | ||
if (_timerType === 'interval') { | ||
scheduleInterval(delay, _timerId, now); | ||
} else if (_timerType === 'timeout') { | ||
scheduleTimeout(delay, _timerId, now); | ||
} else { | ||
throw new Error('The given type "' + type + '" is not supported'); | ||
throw new Error('The given type "' + _timerType + '" is not supported'); | ||
} | ||
} else { | ||
throw new Error('The given action "' + action + '" is not supported'); | ||
throw new Error('The given method "' + data.method + '" is not supported'); | ||
} | ||
@@ -98,0 +106,0 @@ } catch (err) { |
@@ -1,1 +0,1 @@ | ||
!function(){"use strict";var a=new Map,b=new Map,c=function(b){var c=a.get(b);if(void 0===c)throw new Error('There is no interval scheduled with the given id "'+b+'".');clearTimeout(c),a.delete(b)},d=function(a){var c=b.get(a);if(void 0===c)throw new Error('There is no timeout scheduled with the given id "'+a+'".');clearTimeout(c),b.delete(a)},e=function(a,b){var c=void 0;if("performance"in self){var d=performance.now();a-=Math.max(0,d-b),c=d}else c=Date.now();return{delay:a,expected:c+a}},f=function a(b,c,d,e){var f="performance"in self?performance.now():Date.now();f>d?postMessage({id:c,type:e}):b.set(c,setTimeout(a,d-f,b,c,d,e))},g=function(b,c,d){var g=void 0,h=e(b,d);b=h.delay,g=h.expected,a.set(c,setTimeout(f,b,a,c,g,"interval"))},h=function(a,c,d){var g=void 0,h=e(a,d);a=h.delay,g=h.expected,b.set(c,setTimeout(f,a,b,c,g,"timeout"))};addEventListener("message",function(a){var b=a.data,e=b.action,f=b.delay,i=b.id,j=b.now,k=b.type;try{if("clear"===e)if("interval"===k)c(i);else{if("timeout"!==k)throw new Error('The given type "'+k+'" is not supported');d(i)}else{if("set"!==e)throw new Error('The given action "'+e+'" is not supported');if("interval"===k)g(f,i,j);else{if("timeout"!==k)throw new Error('The given type "'+k+'" is not supported');h(f,i,j)}}}catch(a){postMessage({err:{message:a.message}})}})}(); | ||
!function(){"use strict";var a=new Map,b=new Map,c=function(b){var c=a.get(b);if(void 0===c)throw new Error('There is no interval scheduled with the given id "'+b+'".');clearTimeout(c),a.delete(b)},d=function(a){var c=b.get(a);if(void 0===c)throw new Error('There is no timeout scheduled with the given id "'+a+'".');clearTimeout(c),b.delete(a)},e=function(a,b){var c=void 0;if("performance"in self){var d=performance.now();a-=Math.max(0,d-b),c=d}else c=Date.now();return{delay:a,expected:c+a}},f=function a(b,c,d,e){var f="performance"in self?performance.now():Date.now();f>d?postMessage({method:"call",params:{timerId:c,timerType:e}}):b.set(c,setTimeout(a,d-f,b,c,d,e))},g=function(b,c,d){var g=void 0,h=e(b,d);b=h.delay,g=h.expected,a.set(c,setTimeout(f,b,a,c,g,"interval"))},h=function(a,c,d){var g=void 0,h=e(a,d);a=h.delay,g=h.expected,b.set(c,setTimeout(f,a,b,c,g,"timeout"))};addEventListener("message",function(a){var b=a.data;try{if("clear"===b.method){var e=b.id,f=b.params,i=f.timerId,j=f.timerType;if("interval"===j)c(i),postMessage({id:e});else{if("timeout"!==j)throw new Error('The given type "'+j+'" is not supported');d(i),postMessage({id:e})}}else{if("set"!==b.method)throw new Error('The given method "'+b.method+'" is not supported');var k=b.params,l=k.delay,m=k.now,n=k.timerId,o=k.timerType;if("interval"===o)g(l,n,m);else{if("timeout"!==o)throw new Error('The given type "'+o+'" is not supported');h(l,n,m)}}}catch(a){postMessage({err:{message:a.message}})}})}(); |
var scheduledIntervalIdentifiers = new Map(); | ||
var scheduledTimeoutIdentifiers = new Map(); | ||
export var clearScheduledInterval = function (id) { | ||
var identifier = scheduledIntervalIdentifiers.get(id); | ||
export var clearScheduledInterval = function (timerId) { | ||
var identifier = scheduledIntervalIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledIntervalIdentifiers.delete(id); | ||
scheduledIntervalIdentifiers.delete(timerId); | ||
} | ||
else { | ||
throw new Error("There is no interval scheduled with the given id \"" + id + "\"."); | ||
throw new Error("There is no interval scheduled with the given id \"" + timerId + "\"."); | ||
} | ||
}; | ||
export var clearScheduledTimeout = function (id) { | ||
var identifier = scheduledTimeoutIdentifiers.get(id); | ||
export var clearScheduledTimeout = function (timerId) { | ||
var identifier = scheduledTimeoutIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledTimeoutIdentifiers.delete(id); | ||
scheduledTimeoutIdentifiers.delete(timerId); | ||
} | ||
else { | ||
throw new Error("There is no timeout scheduled with the given id \"" + id + "\"."); | ||
throw new Error("There is no timeout scheduled with the given id \"" + timerId + "\"."); | ||
} | ||
@@ -37,23 +37,23 @@ }; | ||
}; | ||
var setTimeoutCallback = function (identifiers, id, expected, type) { | ||
var setTimeoutCallback = function (identifiers, timerId, expected, timerType) { | ||
var now = ('performance' in self) ? performance.now() : Date.now(); | ||
if (now > expected) { | ||
postMessage({ id: id, type: type }); | ||
postMessage({ method: 'call', params: { timerId: timerId, timerType: timerType } }); | ||
} | ||
else { | ||
identifiers.set(id, setTimeout(setTimeoutCallback, (expected - now), identifiers, id, expected, type)); | ||
identifiers.set(timerId, setTimeout(setTimeoutCallback, (expected - now), identifiers, timerId, expected, timerType)); | ||
} | ||
}; | ||
export var scheduleInterval = function (delay, id, nowInMainThread) { | ||
export var scheduleInterval = function (delay, timerId, nowInMainThread) { | ||
var expected; | ||
(_a = computeDelayAndExpectedCallbackTime(delay, nowInMainThread), delay = _a.delay, expected = _a.expected); | ||
scheduledIntervalIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, id, expected, 'interval')); | ||
scheduledIntervalIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, timerId, expected, 'interval')); | ||
var _a; | ||
}; | ||
export var scheduleTimeout = function (delay, id, nowInMainThread) { | ||
export var scheduleTimeout = function (delay, timerId, nowInMainThread) { | ||
var expected; | ||
(_a = computeDelayAndExpectedCallbackTime(delay, nowInMainThread), delay = _a.delay, expected = _a.expected); | ||
scheduledTimeoutIdentifiers.set(id, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, id, expected, 'timeout')); | ||
scheduledTimeoutIdentifiers.set(timerId, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, timerId, expected, 'timeout')); | ||
var _a; | ||
}; | ||
//# sourceMappingURL=/users/chrisguttandin/repositories/worker-timers-worker/node_modules/tsconfig-holy-grail/src/helpers/timer.js.map |
import { clearScheduledInterval, clearScheduledTimeout, scheduleInterval, scheduleTimeout } from './helpers/timer'; | ||
addEventListener('message', function (_a) { | ||
var _b = _a.data, action = _b.action, delay = _b.delay, id = _b.id, now = _b.now, type = _b.type; | ||
var data = _a.data; | ||
try { | ||
if (action === 'clear') { | ||
if (type === 'interval') { | ||
clearScheduledInterval(id); | ||
if (data.method === 'clear') { | ||
var id = data.id, _b = data.params, timerId = _b.timerId, timerType = _b.timerType; | ||
if (timerType === 'interval') { | ||
clearScheduledInterval(timerId); | ||
postMessage({ id: id }); | ||
} | ||
else if (type === 'timeout') { | ||
clearScheduledTimeout(id); | ||
else if (timerType === 'timeout') { | ||
clearScheduledTimeout(timerId); | ||
postMessage({ id: id }); | ||
} | ||
else { | ||
throw new Error("The given type \"" + type + "\" is not supported"); | ||
throw new Error("The given type \"" + timerType + "\" is not supported"); | ||
} | ||
} | ||
else if (action === 'set') { | ||
if (type === 'interval') { | ||
scheduleInterval(delay, id, now); | ||
else if (data.method === 'set') { | ||
var _c = data.params, delay = _c.delay, now = _c.now, timerId = _c.timerId, timerType = _c.timerType; | ||
if (timerType === 'interval') { | ||
scheduleInterval(delay, timerId, now); | ||
} | ||
else if (type === 'timeout') { | ||
scheduleTimeout(delay, id, now); | ||
else if (timerType === 'timeout') { | ||
scheduleTimeout(delay, timerId, now); | ||
} | ||
else { | ||
throw new Error("The given type \"" + type + "\" is not supported"); | ||
throw new Error("The given type \"" + timerType + "\" is not supported"); | ||
} | ||
} | ||
else { | ||
throw new Error("The given action \"" + action + "\" is not supported"); | ||
throw new Error("The given method \"" + data.method + "\" is not supported"); | ||
} | ||
@@ -30,0 +34,0 @@ } |
@@ -62,3 +62,3 @@ { | ||
"types": "build/es2015/module.d.ts", | ||
"version": "2.0.2" | ||
"version": "3.0.0" | ||
} |
@@ -0,23 +1,25 @@ | ||
import { ICallRequest } from '../interfaces'; | ||
const scheduledIntervalIdentifiers: Map<number, number> = new Map(); | ||
const scheduledTimeoutIdentifiers: Map<number, number> = new Map(); | ||
export const clearScheduledInterval = (id: number) => { | ||
const identifier = scheduledIntervalIdentifiers.get(id); | ||
export const clearScheduledInterval = (timerId: number) => { | ||
const identifier = scheduledIntervalIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledIntervalIdentifiers.delete(id); | ||
scheduledIntervalIdentifiers.delete(timerId); | ||
} else { | ||
throw new Error(`There is no interval scheduled with the given id "${ id }".`); | ||
throw new Error(`There is no interval scheduled with the given id "${ timerId }".`); | ||
} | ||
}; | ||
export const clearScheduledTimeout = (id: number) => { | ||
const identifier = scheduledTimeoutIdentifiers.get(id); | ||
export const clearScheduledTimeout = (timerId: number) => { | ||
const identifier = scheduledTimeoutIdentifiers.get(timerId); | ||
if (identifier !== undefined) { | ||
clearTimeout(identifier); | ||
scheduledTimeoutIdentifiers.delete(id); | ||
scheduledTimeoutIdentifiers.delete(timerId); | ||
} else { | ||
throw new Error(`There is no timeout scheduled with the given id "${ id }".`); | ||
throw new Error(`There is no timeout scheduled with the given id "${ timerId }".`); | ||
} | ||
@@ -45,13 +47,13 @@ }; | ||
const setTimeoutCallback = (identifiers: Map<number, number>, id: number, expected: number, type: string) => { | ||
const setTimeoutCallback = (identifiers: Map<number, number>, timerId: number, expected: number, timerType: string) => { | ||
const now = ('performance' in self) ? performance.now() : Date.now(); | ||
if (now > expected) { | ||
postMessage({ id, type }); | ||
postMessage(<ICallRequest> { method: 'call', params: { timerId, timerType } }); | ||
} else { | ||
identifiers.set(id, setTimeout(setTimeoutCallback, (expected - now), identifiers, id, expected, type)); | ||
identifiers.set(timerId, setTimeout(setTimeoutCallback, (expected - now), identifiers, timerId, expected, timerType)); | ||
} | ||
}; | ||
export const scheduleInterval = (delay: number, id: number, nowInMainThread: number) => { | ||
export const scheduleInterval = (delay: number, timerId: number, nowInMainThread: number) => { | ||
let expected; | ||
@@ -62,7 +64,7 @@ | ||
scheduledIntervalIdentifiers.set( | ||
id, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, id, expected, 'interval') | ||
timerId, setTimeout(setTimeoutCallback, delay, scheduledIntervalIdentifiers, timerId, expected, 'interval') | ||
); | ||
}; | ||
export const scheduleTimeout = (delay: number, id: number, nowInMainThread: number) => { | ||
export const scheduleTimeout = (delay: number, timerId: number, nowInMainThread: number) => { | ||
let expected; | ||
@@ -73,4 +75,4 @@ | ||
scheduledTimeoutIdentifiers.set( | ||
id, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, id, expected, 'timeout') | ||
timerId, setTimeout(setTimeoutCallback, delay, scheduledTimeoutIdentifiers, timerId, expected, 'timeout') | ||
); | ||
}; |
@@ -1,26 +0,35 @@ | ||
import { clearScheduledInterval, clearScheduledTimeout, scheduleInterval, scheduleTimeout } from './helpers/timer'; | ||
import { IWorkerTimersEvent } from './interfaces/worker-timers-event'; | ||
import { clearScheduledInterval, clearScheduledTimeout, scheduleInterval, scheduleTimeout } from './helpers/timer'; | ||
import { INotification, IWorkerTimersBrokerEvent } from './interfaces'; | ||
export { IWorkerTimersEvent }; | ||
export * from './interfaces'; | ||
export * from './types'; | ||
addEventListener('message', ({ data: { action, delay, id, now, type } }: IWorkerTimersEvent) => { | ||
addEventListener('message', ({ data }: IWorkerTimersBrokerEvent) => { | ||
try { | ||
if (action === 'clear') { | ||
if (type === 'interval') { | ||
clearScheduledInterval(id); | ||
} else if (type === 'timeout') { | ||
clearScheduledTimeout(id); | ||
if (data.method === 'clear') { | ||
const { id, params: { timerId, timerType } } = data; | ||
if (timerType === 'interval') { | ||
clearScheduledInterval(timerId); | ||
postMessage(<INotification> { id }); | ||
} else if (timerType === 'timeout') { | ||
clearScheduledTimeout(timerId); | ||
postMessage(<INotification> { id }); | ||
} else { | ||
throw new Error(`The given type "${ type }" is not supported`); | ||
throw new Error(`The given type "${ timerType }" is not supported`); | ||
} | ||
} else if (action === 'set') { | ||
if (type === 'interval') { | ||
scheduleInterval(delay, id, now); | ||
} else if (type === 'timeout') { | ||
scheduleTimeout(delay, id, now); | ||
} else if (data.method === 'set') { | ||
const { params: { delay, now, timerId, timerType } } = data; | ||
if (timerType === 'interval') { | ||
scheduleInterval(delay, timerId, now); | ||
} else if (timerType === 'timeout') { | ||
scheduleTimeout(delay, timerId, now); | ||
} else { | ||
throw new Error(`The given type "${ type }" is not supported`); | ||
throw new Error(`The given type "${ timerType }" is not supported`); | ||
} | ||
} else { | ||
throw new Error(`The given action "${ action }" is not supported`); | ||
throw new Error(`The given method "${ (<any> data).method }" is not supported`); | ||
} | ||
@@ -27,0 +36,0 @@ } catch (err) { |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
38247
83
500
0