Skip to content

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

@turbocrime

Description

@turbocrime

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions