Skip to content

Commit 06db603

Browse files
committed
Allow task polling before creation notification arrives
1 parent 486e8ed commit 06db603

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/shared/request.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,21 @@ export class PendingRequest<SendRequestT extends Request, SendNotificationT exte
3636
// Whichever is successful first (or a failure if all fail) is returned.
3737
return Promise.allSettled([
3838
(async () => {
39-
// Blocks for a notifications/tasks/created with the provided task ID
40-
await this.taskCreatedHandle;
41-
await onTaskCreated();
42-
return await this.taskHandler(this.taskId!, {
39+
// Start task handler immediately without waiting for creation notification
40+
const taskPromise = this.taskHandler(this.taskId!, {
4341
onTaskCreated,
4442
onTaskStatus
4543
});
44+
45+
// Call onTaskCreated callback when notification arrives, but don't block taskHandler
46+
// The promise is tied to the lifecycle of taskPromise, so it won't leak
47+
this.taskCreatedHandle
48+
.then(() => onTaskCreated())
49+
.catch(() => {
50+
// Silently ignore if notification never arrives or fails
51+
});
52+
53+
return await taskPromise;
4654
})(),
4755
this.resultHandle
4856
]).then(([task, result]) => {

0 commit comments

Comments
 (0)