Skip to content

Commit

Permalink
core:frontend:helper: Remove callPeriodically
Browse files Browse the repository at this point in the history
* Remove callPeriodycally and stopCallPeriodically to prefer using of
  OneMoreTime when intervals are needed
  • Loading branch information
JoaoMario109 authored and joaoantoniocardoso committed Sep 30, 2024
1 parent f27c983 commit 08f7e38
Showing 1 changed file with 0 additions and 35 deletions.
35 changes: 0 additions & 35 deletions core/frontend/src/utils/helper_functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,6 @@ export function sleep(interval: number): Promise<number> {
return new Promise((resolve) => setTimeout(resolve, interval))
}

const periodic_tasks_counter: Map<() => Promise<void>, number> = new Map()

/* Call a given function periodically for a given interval. */
/**
* @param func - Function to be called.
* @param interval - Time in milliseconds to wait after the previous request is done
* */
export async function callPeriodically(
func: () => Promise<void>,
interval: number,
automated_call?: boolean,
): Promise<void> {
let current_count = periodic_tasks_counter.get(func) ?? 0
if (!automated_call) {
current_count += 1
periodic_tasks_counter.set(func, current_count)
}
if (current_count <= 0) {
periodic_tasks_counter.set(func, 0)
return
}
await func()
await sleep(interval)
callPeriodically(func, interval, true)
}

/* Stop Callingg a given function periodically. */
/**
* @param function_name - Function to be called.
* */
export function stopCallingPeriodically(func: () => Promise<void>): void {
const current_count = periodic_tasks_counter.get(func) ?? 1
periodic_tasks_counter.set(func, current_count - 1)
}

/* Cast a string into a proper javascript type. */
/**
* @param value - String to be cast
Expand Down

0 comments on commit 08f7e38

Please sign in to comment.