Interface AbortResolver

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

Properties

controller: (<T, C, R>(this: C & WretchResponseChain<T, C, R>) => [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, R>(this: C & WretchResponseChain<T, C, R>, cb: WretchErrorCallback<T, C, R>) => this)

Catches an AbortError and performs a callback.

setTimeout: (<T, C, R>(this: C & WretchResponseChain<T, C, R>, time: number, controller?: AbortController) => this)

Aborts the request after a fixed time.

If you use a custom AbortController associated with the request, pass it as the second argument.

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

Type declaration

    • <T, C, R>(this, time, controller?): this
    • Type Parameters

      Parameters

      • this: C & WretchResponseChain<T, C, R>
      • time: number

        Time in milliseconds

      • Optionalcontroller: AbortController

        An instance of AbortController

      Returns this