From f1b9879cbc44b9e59ba4248c1c95771b4dfdc6e8 Mon Sep 17 00:00:00 2001 From: Spartak Date: Fri, 21 Jun 2024 18:18:31 +0200 Subject: [PATCH] 0.1.1 --- docs/functions/to.html | 4 ++-- docs/index.html | 14 ++++++++++---- docs/types/_internal_.ToFinally.html | 2 +- docs/types/_internal_.ToIn.html | 2 +- docs/types/_internal_.ToOut.html | 2 +- package.json | 2 +- 6 files changed, 16 insertions(+), 10 deletions(-) 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