@@ -10,11 +10,72 @@ class HttpsCallableOptions {
1010 /// Defaults [limitedUseAppCheckToken] to `false`
1111 HttpsCallableOptions (
1212 {this .timeout = const Duration (seconds: 60 ),
13- this .limitedUseAppCheckToken = false });
13+ this .limitedUseAppCheckToken = false ,
14+ this .webAbortSignal});
1415
1516 /// Returns the timeout for this instance
1617 Duration timeout;
1718
1819 /// Sets whether or not to use limited-use App Check tokens when invoking the associated function.
1920 bool limitedUseAppCheckToken;
21+
22+ /// An AbortSignal that can be used to cancel the streaming response.
23+ /// When the signal is aborted, the underlying HTTP connection will be terminated.
24+ AbortSignal ? webAbortSignal;
25+ }
26+
27+ /// Represents a base class for encapsulating abort signals.
28+ sealed class AbortSignal {}
29+
30+ /// Creates an [AbortSignal] that will automatically abort after a specified [time] .
31+ ///
32+ /// This is equivalent to calling `AbortSignal.timeout(ms)` in the Web SDK.
33+ ///
34+ /// Typically used to cancel long-running operations after a timeout duration.
35+ ///
36+ /// Example:
37+ /// ```dart
38+ /// final signal = HttpsCallableOptions(webAbortSignal: TimeLimit(Duration(seconds: 10)));
39+ /// ```
40+ class TimeLimit extends AbortSignal {
41+ final Duration time;
42+ TimeLimit (this .time);
43+ }
44+
45+ /// Creates an [AbortSignal] that is immediately aborted with an optional [reason] .
46+ ///
47+ /// This is equivalent to calling `AbortSignal.abort(reason)` in the Web SDK.
48+ ///
49+ /// Useful when you want to explicitly cancel a callable before it begins, or to provide
50+ /// a specific reason for cancellation.
51+ ///
52+ /// Example:
53+ /// ```dart
54+ /// final signal = HttpsCallableOptions(webAbortSignal: Abort('User exited'));
55+ /// ```
56+
57+ class Abort extends AbortSignal {
58+ final Object ? reason;
59+ Abort ([this .reason]);
60+ }
61+
62+ /// Creates an [AbortSignal] that is aborted when **any** of the provided [signals] is aborted.
63+ ///
64+ /// This is equivalent to calling `AbortSignal.any([...])` in the Web SDK.
65+ ///
66+ /// Useful for combining multiple abort conditions.
67+ ///
68+ /// Example:
69+ /// ```dart
70+ /// final signal = HttpsCallableOptions(
71+ /// webAbortSignal: Any([
72+ /// TimeLimit(Duration(seconds: 10)),
73+ /// Abort('User cancelled'),
74+ /// ]),
75+ /// );
76+ /// ```
77+
78+ class Any extends AbortSignal {
79+ final List <AbortSignal > signals;
80+ Any (this .signals);
2081}
0 commit comments