Function: awaitTo()

awaitTo<T>(promise): Promise<[unknown, T | undefined]>

A helper function that wraps a Promise and returns a tuple of [error, data]. If the Promise resolves successfully, the first element of the tuple will be null, and the second element will be the resolved value. If the Promise is rejected, the first element of the tuple will be the error, and the second element will be undefined.

Type Parameters

T

T

Parameters

promise

Promise<T>

The Promise to wrap.

Returns

Promise<[unknown, T | undefined]>

A Promise that resolves to a tuple of [error, data].