wretch
    Preparing search index...

    Interface AbortResolver

    interface AbortResolver {
        controller: <T, C extends AbortResolver, R, E>(
            this: C & WretchResponseChain<T, C, R, E>,
        ) => [any, AbortResolver];
        onAbort: <T, C extends AbortResolver, R, E>(
            this: C & WretchResponseChain<T, C, R, E>,
            cb: WretchErrorCallback<T, C, R, E>,
        ) => this;
        setTimeout: <T, C extends AbortResolver, R, E>(
            this: C & WretchResponseChain<T, C, R, E>,
            time: number,
            options?: SetTimeoutOptions,
        ) => this;
    }
    Index

    Properties

    controller: <T, C extends AbortResolver, R, E>(
        this: C & WretchResponseChain<T, C, R, E>,
    ) => [any, AbortResolver]

    Returns the provided or generated AbortController plus the wretch response chain as a pair.

    // We need the controller outside the chain
    const [c, w] = wretch("url")
    .addon(AbortAddon())
    .get()
    .controller()

    // Resume with the chain
    w.onAbort(_ => console.log("ouch")).json()

    // Later on…
    c.abort()
    onAbort: <T, C extends AbortResolver, R, E>(
        this: C & WretchResponseChain<T, C, R, E>,
        cb: WretchErrorCallback<T, C, R, E>,
    ) => this

    Catches an AbortError and performs a callback.

    setTimeout: <T, C extends AbortResolver, R, E>(
        this: C & WretchResponseChain<T, C, R, E>,
        time: number,
        options?: SetTimeoutOptions,
    ) => this

    Aborts the request after a fixed time.

    If you use a custom AbortController associated with the request, pass it in the options object.

    // 1 second timeout
    wretch("...").addon(AbortAddon()).get().setTimeout(1000).json(_ =>
    // will not be called if the request timeouts
    )

    // With custom controller
    wretch("...").addon(AbortAddon()).get().setTimeout(1000, { controller }).json()

    Type Declaration