fantasy-manager/Modules/locked.ts
Lukas Schaefer d3a5fe88f9
switch to kysely (#863)
Signed-off-by: Lukas Schaefer <lukas@lschaefer.xyz>
2025-05-09 19:12:32 -04:00

21 lines
601 B
TypeScript

import db from "#database";
/**
* Waits until the specified league is not locked.
*
* This function is meant to be used to prevent player data from being accessed while the league is locked.
* It waits until the specified league is not locked, then returns.
*
* @param league - The league to wait for.
*/
export async function whileLocked(league: string) {
while (
(await db
.selectFrom("data")
.select("value1")
.where("value1", "=", `locked${league}`)
.executeTakeFirst()) !== undefined
) {
await new Promise((resolve) => setTimeout(resolve, 500));
}
}