Skip to content

Commit 4018bc1

Browse files
committed
Handle request cancellation during duplicate API calls by propagating cancel token rejections
1 parent 90c47e4 commit 4018bc1

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎apps/editor/src/services/api-manager.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ApiManager {
5656
}
5757
}
5858

59-
if (!previous_waiting || previous_waiting.body_hash !== body_hash) {
59+
if (!previous_waiting || previous_waiting.body_hash != body_hash) {
6060
this.waiting_chain.set(params.endpoint_url, {
6161
promise: current_promise,
6262
resolve: resolve_current,
@@ -74,8 +74,14 @@ export class ApiManager {
7474
reasoning_effort: params.reasoning_effort
7575
})
7676

77-
if (previous_waiting && previous_waiting.body_hash === body_hash) {
78-
await previous_waiting.promise
77+
if (previous_waiting && previous_waiting.body_hash == body_hash) {
78+
if (cancel_token_source.token.reason) {
79+
throw cancel_token_source.token.reason
80+
}
81+
await Promise.race([
82+
previous_waiting.promise,
83+
cancel_token_source.token.promise.then((c) => Promise.reject(c))
84+
])
7985
}
8086

8187
const result = await make_api_request({

0 commit comments

Comments
 (0)