Support multiple abort signals and refactor signal/timeout controllers#11
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (14)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
9d125fa to
b627ab2
Compare
7e4db2d to
9eac38d
Compare
Greptile SummaryThis PR successfully refactors signal and timeout handling to support multiple abort signals while improving the internal architecture. Key improvements:
Architecture notes:
Confidence Score: 5/5
Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class TryBuilder {
-BuilderConfig config
+signal(AbortSignal) TryBuilder
+timeout(TimeoutOptions) TryBuilder
+run(tryFn) T|E
+runAsync(tryFn) Promise
}
class RunExecution {
-TimeoutController timeout
-SignalController signal
-TryCtx ctx
+execute() Result
-race(promise) Promise
+dispose() void
}
class SignalController {
+AbortSignal signal
+constructor(signals)
+checkDidCancel() CancellationError
+race(promise) Promise
+dispose() void
}
class TimeoutController {
+AbortSignal signal
-AbortController controller
-number timeoutId
+constructor(TimeoutPolicy)
+checkDidTimeout() TimeoutError
+race(promise) Promise
+dispose() void
}
class BuilderConfig {
+signals AbortSignal[]
+timeout TimeoutPolicy
+retry RetryPolicy
+wraps WrapFn[]
}
TryBuilder --> BuilderConfig : uses
RunExecution --> TimeoutController : creates
RunExecution --> SignalController : creates
SignalController --> AbortSignal : combines via any()
TimeoutController --> AbortController : manages
RunExecution --> BuilderConfig : receives
Last reviewed commit: eb9688f |
b627ab2 to
0d6daf5
Compare
9eac38d to
6a202b7
Compare
0d6daf5 to
c2d4c9d
Compare
6a202b7 to
02d9642
Compare
c2d4c9d to
4f6880e
Compare
02d9642 to
4c46ca6
Compare
4f6880e to
e636621
Compare
4c46ca6 to
030906e
Compare
030906e to
eb9688f
Compare

This pull request refactors signal handling to support multiple abort signals and improves the internal architecture of timeout and signal controllers.
Key Changes:
Multiple Signal Support: The
signal()method now accumulates multiple abort signals instead of replacing them. The builder config now usessignalsarray instead of a singlesignalproperty.Combined Signal Context: When multiple signals are configured via chained
.signal()calls, they are combined into a compound signal available asctx.signalusingAbortSignal.any().Controller Refactoring:
createTimeoutController()andcreateSignalController()factory functions toTimeoutControllerandSignalControllerclassesSymbol.disposesupportAbortSignal.any()instead of manual event forwardingAPI Simplification:
createDisposertodisposefor the exported functioncontext.tsmodule, moving context creation inlineraceWithTimeout/raceWithSignalto simplyraceEnhanced Testing: Added comprehensive tests for multiple signal scenarios, ensuring any configured signal can trigger cancellation during async operations.
The changes maintain backward compatibility for single signal usage while enabling more flexible cancellation patterns through signal composition.
Greptile Summary
Refactored signal and timeout handling to support multiple abort signals with improved architecture using native
AbortSignal.any()and class-based controllers.Major changes:
.signal()method now accumulates signals into an array instead of replacing, enabling signal compositionSignalControllerandTimeoutControllerconverted from factory functions to classes with proper disposable patternsAbortSignal.any()to combine multiple signals intoctx.signal, simplifying internal implementationraceWithTimeout/raceWithSignaltorace()context.tsmodule, inlined context creation intoRunExecutioncreateDisposertodisposefor cleaner APIConfidence Score: 5/5
AbortSignal.any()), follows modern disposable patterns, and reduces code complexity while adding functionalityImportant Files Changed
AbortSignal.any()for combining signals, with simplified disposal patternDisposableStackDisposableStacksignal()method to accumulate signals into array instead of replacing single signalsignalproperty tosignalsarray to support multiple abort signalsctx.signalcombines signals usingAbortSignal.any()Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[User calls .signal] --> B[Builder accumulates into signals array] B --> C[RunExecution creates TimeoutController] C --> D[Merges timeout.signal with config.signals] D --> E[SignalController created with merged array] E --> F[AbortSignal.any combines into compound signal] F --> G[ctx.signal available to user code] G --> H{Any signal aborts?} H -->|Yes| I[Race resolves to CancellationError] H -->|No| J[Promise completes normally] I --> K[Cleanup via DisposableStack] J --> KLast reviewed commit: 7e4db2d