fix: Bind abort controller to abort in sdk (#9341)
This commit is contained in:
1 parent
bd4d2fd554
commit
262aa4291a
1 file changed
+5
-4
@@ -136,19 +136,20 @@ export class Client {
|
|||||||
input: FetchInput,
|
input: FetchInput,
|
||||||
init?: FetchArgs
|
init?: FetchArgs
|
||||||
): Promise<FetchStreamResponse> {
|
): Promise<FetchStreamResponse> {
|
||||||
let abort = new AbortController()
|
const abortController = new AbortController()
|
||||||
|
const abortFunc = abortController.abort.bind(abortController)
|
||||||
|
|
||||||
let res = await this.fetch_(input, {
|
let res = await this.fetch_(input, {
|
||||||
...init,
|
...init,
|
||||||
signal: abort.signal,
|
signal: abortController.signal,
|
||||||
headers: { ...init?.headers, accept: "text/event-stream" },
|
headers: { ...init?.headers, accept: "text/event-stream" },
|
||||||
})
|
})
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
return { stream: events(res, abort.signal), abort: abort.abort }
|
return { stream: events(res, abortController.signal), abort: abortFunc }
|
||||||
}
|
}
|
||||||
|
|
||||||
return { stream: null, abort: abort.abort }
|
return { stream: null, abort: abortFunc }
|
||||||
}
|
}
|
||||||
|
|
||||||
setToken(token: string) {
|
setToken(token: string) {
|
||||||
|
|||||||
Reference in new issue
Block a user