@@ -7,41 +7,6 @@ export function sleep(interval: number): Promise<number> {
77 return new Promise ( ( resolve ) => setTimeout ( resolve , interval ) )
88}
99
10- const periodic_tasks_counter : Map < ( ) => Promise < void > , number > = new Map ( )
11-
12- /* Call a given function periodically for a given interval. */
13- /**
14- * @param func - Function to be called.
15- * @param interval - Time in milliseconds to wait after the previous request is done
16- * */
17- export async function callPeriodically (
18- func : ( ) => Promise < void > ,
19- interval : number ,
20- automated_call ?: boolean ,
21- ) : Promise < void > {
22- let current_count = periodic_tasks_counter . get ( func ) ?? 0
23- if ( ! automated_call ) {
24- current_count += 1
25- periodic_tasks_counter . set ( func , current_count )
26- }
27- if ( current_count <= 0 ) {
28- periodic_tasks_counter . set ( func , 0 )
29- return
30- }
31- await func ( )
32- await sleep ( interval )
33- callPeriodically ( func , interval , true )
34- }
35-
36- /* Stop Callingg a given function periodically. */
37- /**
38- * @param function_name - Function to be called.
39- * */
40- export function stopCallingPeriodically ( func : ( ) => Promise < void > ) : void {
41- const current_count = periodic_tasks_counter . get ( func ) ?? 1
42- periodic_tasks_counter . set ( func , current_count - 1 )
43- }
44-
4510/* Cast a string into a proper javascript type. */
4611/**
4712 * @param value - String to be cast
0 commit comments