Skip to content

API Reference / @gtkx/runtime / promisify

Variable: promisify

const promisify: <R, T>(asyncFn, finish, cancellable, ...leading) => Promise<T>

Defined in: runtime/dist/promisify.d.ts:12

Wraps a GIO-style asynchronous function that takes a completion callback into a promise, invoking the finish function to extract the result. Outside production, the call site's stack is captured and attached as the rejection error's cause.

Type Parameters

R

R extends object

T

T

Parameters

asyncFn

(...args) => void

The async function, called with the leading arguments, the cancellable, and a completion callback.

finish

(result) => T

Extracts the result from the async result passed to the completion callback.

cancellable

object | null | undefined

A cancellable object, or null/undefined for none.

leading

...unknown[]

Arguments passed to asyncFn before the cancellable and callback.

Returns

Promise<T>

A promise resolving to the finished result, or rejecting if finish throws.

Released under the MPL-2.0 License.