Interface AbortResolver

Hierarchy

  • AbortResolver

Properties

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

Type declaration

    • <T, C, R>(this): [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()

      Type Parameters

      Parameters

      Returns [any, AbortResolver]

onAbort: (<T, C, R>(this, cb) => AbortResolver)

Type declaration

setTimeout: (<T, C, R>(this, time, controller?) => AbortResolver)

Type declaration

    • <T, C, R>(this, time, controller?): AbortResolver
    • 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 Parameters

      Parameters

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

        Time in milliseconds

      • Optional controller: AbortController

        An instance of AbortController

      Returns AbortResolver

Generated using TypeDoc