Add Prettier and ESLint tooling (Refs #77)
This commit is contained in:
@@ -3,11 +3,17 @@ import { AsyncLocalStorage } from 'node:async_hooks';
|
||||
const requester = new AsyncLocalStorage<{ username: string | null; active: boolean }>();
|
||||
|
||||
/** Use only the authenticated session, and stop attribution when the request finishes. */
|
||||
export async function withRequestUsername<T>(username: string | null, work: () => T | Promise<T>): Promise<T> {
|
||||
export async function withRequestUsername<T>(
|
||||
username: string | null,
|
||||
work: () => T | Promise<T>
|
||||
): Promise<T> {
|
||||
const context = { username, active: true };
|
||||
return requester.run(context, async () => {
|
||||
try { return await work(); }
|
||||
finally { context.active = false; }
|
||||
try {
|
||||
return await work();
|
||||
} finally {
|
||||
context.active = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user