Skip to content

LockManager.request returns Promise<any> but should resolve the return type of its callback parameter #1946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
turbocrime opened this issue Mar 24, 2025 · 0 comments · Fixed by #1947

Comments

@turbocrime
Copy link
Contributor

it does look like the class spec describes the present types https://w3c.github.io/web-locks/#lockmanager

but reading the english description of behavior, https://w3c.github.io/web-locks/#api-lock-manager-request

The callback (final argument) is a callback function invoked with the Lock when granted. This is specified by script, and is usually an async function. The lock is held until the callback function completes. If a non-async callback function is passed in, then it is automatically wrapped in a promise that resolves immediately, so the lock is only held for the duration of the synchronous callback.

The returned promise resolves (or rejects) with the result of the callback after the lock is released, or rejects if the request is aborted.

it seems like the baseline should be

interface LockManager {
    query(): Promise<LockManagerSnapshot>;
    request<T>(name: string, callback: LockGrantedCallback<T>): Promise<T>;
    request<T>(name: string, options: LockOptions, callback: LockGrantedCallback<T>): Promise<T>;
}

interface LockGrantedCallback<T> {
    (lock: Lock | null): T;
}

which seems to be how the method actually behaves.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant