@@ -31,70 +31,37 @@ export class TimeoutError extends Error {
3131 }
3232}
3333
34- /**
35- * Unsupported platform error, which is thrown when the module is used
36- * neither from a web browser nor from Node.js
37- * @public
38- * @class
39- * @exception
40- * @category Exceptions
41- */
42- export class UnsupportedPlatformError extends Error {
43- /**
44- * Creates an UnsupportedPlatformError instance
45- * @public
46- */
47- constructor ( ) {
48- super ( 'Unsupported platform' ) ;
49-
50- Object . setPrototypeOf ( this , UnsupportedPlatformError . prototype ) ;
51- }
52- }
53-
5434/**
5535 * A utility function for cross-platform type-safe scheduling
5636 * @private
5737 * @returns Returns a proper scheduler instance depending on the current environment
58- * @throws [[UnsupportedPlatformError]] If the current environment is not supported, e.g. it's neither a web browser nor Node.js
5938 * @throws Error
6039 * @category Utilities
6140 */
62- const getScheduler = ( ) : Scheduler => {
63- if (
64- // Not a web browser
65- window == null ||
66- // Not Node.js
67- module == null ||
68- global == null
69- ) {
70- throw new UnsupportedPlatformError ( ) ;
71- }
41+ const getScheduler = ( ) : Scheduler => ( {
42+ schedule : ( fn , interval ) => {
43+ let scheduledTimer : number | NodeJS . Timeout | undefined = undefined ;
7244
73- return {
74- schedule : ( fn , interval ) => {
75- let scheduledTimer : number | NodeJS . Timeout | undefined = undefined ;
76-
77- const cleanUp = ( timer : number | NodeJS . Timeout | undefined ) => {
78- if ( timer != null ) {
79- ( window != null ? window : global ) . clearTimeout ( timer as number ) ;
80- }
45+ const cleanUp = ( timer : number | NodeJS . Timeout | undefined ) => {
46+ if ( timer != null ) {
47+ clearTimeout ( timer as number ) ;
48+ }
8149
82- scheduledTimer = undefined ;
83- } ;
50+ scheduledTimer = undefined ;
51+ } ;
8452
85- const iteration = ( ) => {
86- cleanUp ( scheduledTimer ) ;
87- fn ( ) ;
88- } ;
53+ const iteration = ( ) => {
54+ cleanUp ( scheduledTimer ) ;
55+ fn ( ) ;
56+ } ;
8957
90- scheduledTimer = ( window != null ? window : global ) . setTimeout ( iteration , interval ) ;
58+ scheduledTimer = setTimeout ( iteration , interval ) ;
9159
92- return {
93- cancel : ( ) => cleanUp ( scheduledTimer ) ,
94- } ;
95- } ,
96- } ;
97- } ;
60+ return {
61+ cancel : ( ) => cleanUp ( scheduledTimer ) ,
62+ } ;
63+ } ,
64+ } ) ;
9865
9966/**
10067 * Delays the execution by the given interval, in milliseconds
0 commit comments