mirror of
https://github.com/appium/appium.git
synced 2026-10-26 02:29:38 +08:00
18 lines
475 B
TypeScript
18 lines
475 B
TypeScript
/**
|
|
* A stopwatch-like thing
|
|
*
|
|
* Used for displaying elapsed time in milliseconds
|
|
* @param id - Unique identifier
|
|
* @returns Function that returns the elapsed time in milliseconds
|
|
*/
|
|
export function stopwatch(id: string) {
|
|
const start = Date.now();
|
|
stopwatch.cache.set(id, start);
|
|
return () => {
|
|
const result = Date.now() - (stopwatch.cache.get(id) ?? 0);
|
|
stopwatch.cache.delete(id);
|
|
return result;
|
|
};
|
|
}
|
|
stopwatch.cache = new Map<string, number>();
|