diff --git a/docs/functions/to.html b/docs/functions/to.html index 9ecdd04..3de12bc 100644 --- a/docs/functions/to.html +++ b/docs/functions/to.html @@ -158,13 +158,13 @@ }
  • Wraps a promise and returns a tuple with either an error or the result. Optionally executes a finally callback after the promise settles.

    -

    Example


    import { to } from "@mrspartak/promises"
    import { api } from "./api"

    // Simple tuple destructuring
    const [apiError, user] = await to(api.get("/me"))

    // Using finally
    $component.isLoading = true
    const [apiError, status] = await to(api.post("/me/status", { status: "online" }), () => {
    $component.isLoading = false
    }) +

    Example


    import { to } from "@mrspartak/promises"
    import { api } from "./api"

    // Simple tuple destructuring
    const [apiError, user] = await to(api.get("/me"))
    if (apiError) {
    // Handle error
    }

    // Using finally
    $component.isLoading = true
    const [apiError, status] = await to(api.post("/me/status", { status: "online" }), () => {
    $component.isLoading = false
    })
    if (apiError) {
    // Handle error
    }

    Type Parameters

    • $Promise

      The type of the value the input promise resolves to.

    Parameters

    • promise: ToIn<$Promise>

      The input promise to be wrapped.

    • Optional _finally: ToFinally

      Optional finally callback to be executed after the promise settles.

    Returns Promise<ToOut<$Promise>>

    A promise that resolves to a tuple containing either an error or the result.

    -
ToFinally: (() => void | Promise<void>)

Type alias for a function that can optionally be executed after the promise resolves or rejects. It can return void or a Promise that resolves to void.

-

Type declaration

    • (): void | Promise<void>
    • Returns void | Promise<void>

ToIn<T>: Promise<T>

Type alias for a promise of type T.

-

Type Parameters

  • T
ToOut<T>: [Error, null] | [null, T]

Type alias for the output of the to function. It can be either an array with an Error and null, or an array with null and the result of type T.

-

Type Parameters

  • T