-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2167 from langchain-ai/dqbd/sdk-js-timeout
feat(sdk-js): implement abort signal timeout, make default timeout for runs 5 minutes
- Loading branch information
Showing
2 changed files
with
51 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export function mergeSignals(...signals: (AbortSignal | null | undefined)[]) { | ||
const nonZeroSignals = signals.filter( | ||
(signal): signal is AbortSignal => signal != null, | ||
); | ||
|
||
if (nonZeroSignals.length === 0) return undefined; | ||
if (nonZeroSignals.length === 1) return nonZeroSignals[0]; | ||
|
||
const controller = new AbortController(); | ||
for (const signal of signals) { | ||
if (signal?.aborted) { | ||
controller.abort(signal.reason); | ||
return controller.signal; | ||
} | ||
|
||
signal?.addEventListener("abort", () => controller.abort(signal.reason), { | ||
once: true, | ||
}); | ||
} | ||
|
||
return controller.signal; | ||
} |