Skip to content

Commit e7c4400

Browse files
feat: AbortController to signal request timeouts
This commit adds a nodejs AbortController to the HTTP request object that is used to signal cancellation for a function execution in the event of a timeout or client disconnect.
1 parent 1fe0f1d commit e7c4400

File tree

14 files changed

+514
-215
lines changed

14 files changed

+514
-215
lines changed

docs/generated/api.json

Lines changed: 128 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"toolPackage": "@microsoft/api-extractor",
4-
"toolVersion": "7.34.4",
4+
"toolVersion": "7.43.1",
55
"schemaVersion": 1011,
66
"oldestForwardsCompatibleVersion": 1001,
77
"tsdocConfig": {
@@ -173,17 +173,29 @@
173173
"preserveMemberOrder": false,
174174
"members": [
175175
{
176-
"kind": "Variable",
177-
"canonicalReference": "@google-cloud/functions-framework!cloudEvent:var",
176+
"kind": "Function",
177+
"canonicalReference": "@google-cloud/functions-framework!cloudEvent:function(1)",
178178
"docComment": "/**\n * Register a function that handles CloudEvents.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to trigger when handling CloudEvents\n *\n * @public\n */\n",
179179
"excerptTokens": [
180180
{
181181
"kind": "Content",
182-
"text": "cloudEvent: "
182+
"text": "cloudEvent: <T = "
183183
},
184184
{
185185
"kind": "Content",
186-
"text": "<T = unknown>(functionName: string, handler: "
186+
"text": "unknown"
187+
},
188+
{
189+
"kind": "Content",
190+
"text": ">(functionName: "
191+
},
192+
{
193+
"kind": "Content",
194+
"text": "string"
195+
},
196+
{
197+
"kind": "Content",
198+
"text": ", handler: "
187199
},
188200
{
189201
"kind": "Reference",
@@ -192,17 +204,56 @@
192204
},
193205
{
194206
"kind": "Content",
195-
"text": "<T>) => void"
207+
"text": "<T>"
208+
},
209+
{
210+
"kind": "Content",
211+
"text": ") => "
212+
},
213+
{
214+
"kind": "Content",
215+
"text": "void"
196216
}
197217
],
198218
"fileUrlPath": "src/function_registry.ts",
199-
"isReadonly": true,
219+
"returnTypeTokenRange": {
220+
"startIndex": 8,
221+
"endIndex": 9
222+
},
200223
"releaseTag": "Public",
201-
"name": "cloudEvent",
202-
"variableTypeTokenRange": {
203-
"startIndex": 1,
204-
"endIndex": 4
205-
}
224+
"overloadIndex": 1,
225+
"parameters": [
226+
{
227+
"parameterName": "functionName",
228+
"parameterTypeTokenRange": {
229+
"startIndex": 3,
230+
"endIndex": 4
231+
},
232+
"isOptional": false
233+
},
234+
{
235+
"parameterName": "handler",
236+
"parameterTypeTokenRange": {
237+
"startIndex": 5,
238+
"endIndex": 7
239+
},
240+
"isOptional": false
241+
}
242+
],
243+
"typeParameters": [
244+
{
245+
"typeParameterName": "T",
246+
"constraintTokenRange": {
247+
"startIndex": 0,
248+
"endIndex": 0
249+
},
250+
"defaultTypeTokenRange": {
251+
"startIndex": 1,
252+
"endIndex": 2
253+
}
254+
}
255+
],
256+
"name": "cloudEvent"
206257
},
207258
{
208259
"kind": "Interface",
@@ -896,17 +947,21 @@
896947
}
897948
},
898949
{
899-
"kind": "Variable",
900-
"canonicalReference": "@google-cloud/functions-framework!http:var",
950+
"kind": "Function",
951+
"canonicalReference": "@google-cloud/functions-framework!http:function(1)",
901952
"docComment": "/**\n * Register a function that responds to HTTP requests.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to invoke when handling HTTP requests\n *\n * @public\n */\n",
902953
"excerptTokens": [
903954
{
904955
"kind": "Content",
905-
"text": "http: "
956+
"text": "http: (functionName: "
906957
},
907958
{
908959
"kind": "Content",
909-
"text": "(functionName: string, handler: "
960+
"text": "string"
961+
},
962+
{
963+
"kind": "Content",
964+
"text": ", handler: "
910965
},
911966
{
912967
"kind": "Reference",
@@ -915,17 +970,39 @@
915970
},
916971
{
917972
"kind": "Content",
918-
"text": ") => void"
973+
"text": ") => "
974+
},
975+
{
976+
"kind": "Content",
977+
"text": "void"
919978
}
920979
],
921980
"fileUrlPath": "src/function_registry.ts",
922-
"isReadonly": true,
981+
"returnTypeTokenRange": {
982+
"startIndex": 5,
983+
"endIndex": 6
984+
},
923985
"releaseTag": "Public",
924-
"name": "http",
925-
"variableTypeTokenRange": {
926-
"startIndex": 1,
927-
"endIndex": 4
928-
}
986+
"overloadIndex": 1,
987+
"parameters": [
988+
{
989+
"parameterName": "functionName",
990+
"parameterTypeTokenRange": {
991+
"startIndex": 1,
992+
"endIndex": 2
993+
},
994+
"isOptional": false
995+
},
996+
{
997+
"parameterName": "handler",
998+
"parameterTypeTokenRange": {
999+
"startIndex": 3,
1000+
"endIndex": 4
1001+
},
1002+
"isOptional": false
1003+
}
1004+
],
1005+
"name": "http"
9291006
},
9301007
{
9311008
"kind": "Interface",
@@ -1757,6 +1834,34 @@
17571834
"name": "Request_2",
17581835
"preserveMemberOrder": false,
17591836
"members": [
1837+
{
1838+
"kind": "PropertySignature",
1839+
"canonicalReference": "@google-cloud/functions-framework!Request_2#abortController:member",
1840+
"docComment": "/**\n * An AbortController used to signal cancellation of a function invocation (e.g. in case of time out).\n */\n",
1841+
"excerptTokens": [
1842+
{
1843+
"kind": "Content",
1844+
"text": "abortController?: "
1845+
},
1846+
{
1847+
"kind": "Reference",
1848+
"text": "AbortController",
1849+
"canonicalReference": "!AbortController:interface"
1850+
},
1851+
{
1852+
"kind": "Content",
1853+
"text": ";"
1854+
}
1855+
],
1856+
"isReadonly": false,
1857+
"isOptional": true,
1858+
"releaseTag": "Public",
1859+
"name": "abortController",
1860+
"propertyTypeTokenRange": {
1861+
"startIndex": 1,
1862+
"endIndex": 2
1863+
}
1864+
},
17601865
{
17611866
"kind": "PropertySignature",
17621867
"canonicalReference": "@google-cloud/functions-framework!Request_2#executionId:member",
@@ -1874,47 +1979,6 @@
18741979
}
18751980
]
18761981
},
1877-
{
1878-
"kind": "Variable",
1879-
"canonicalReference": "@google-cloud/functions-framework!typed:var",
1880-
"docComment": "/**\n * Register a function that handles strongly typed invocations.\n *\n * @param functionName - the name of the function\n *\n * @param handler - the function to trigger\n */\n",
1881-
"excerptTokens": [
1882-
{
1883-
"kind": "Content",
1884-
"text": "typed: "
1885-
},
1886-
{
1887-
"kind": "Content",
1888-
"text": "<T, U>(functionName: string, handler: "
1889-
},
1890-
{
1891-
"kind": "Reference",
1892-
"text": "TypedFunction",
1893-
"canonicalReference": "@google-cloud/functions-framework!TypedFunction:interface"
1894-
},
1895-
{
1896-
"kind": "Content",
1897-
"text": "<T, U> | ((req: T) => U | "
1898-
},
1899-
{
1900-
"kind": "Reference",
1901-
"text": "Promise",
1902-
"canonicalReference": "!Promise:interface"
1903-
},
1904-
{
1905-
"kind": "Content",
1906-
"text": "<U>)) => void"
1907-
}
1908-
],
1909-
"fileUrlPath": "src/function_registry.ts",
1910-
"isReadonly": true,
1911-
"releaseTag": "Public",
1912-
"name": "typed",
1913-
"variableTypeTokenRange": {
1914-
"startIndex": 1,
1915-
"endIndex": 6
1916-
}
1917-
},
19181982
{
19191983
"kind": "Interface",
19201984
"canonicalReference": "@google-cloud/functions-framework!TypedFunction:interface",

docs/generated/api.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export interface LegacyEvent {
112112

113113
// @public (undocumented)
114114
interface Request_2 extends Request_3 {
115+
abortController?: AbortController;
115116
executionId?: string;
116117
rawBody?: Buffer;
117118
spanId?: string;
@@ -121,7 +122,9 @@ export { Request_2 as Request }
121122

122123
export { Response_2 as Response }
123124

124-
// @public
125+
// Warning: (ae-internal-missing-underscore) The name "typed" should be prefixed with an underscore because the declaration is marked as @internal
126+
//
127+
// @internal
125128
export const typed: <T, U>(functionName: string, handler: TypedFunction<T, U> | ((req: T) => U | Promise<U>)) => void;
126129

127130
// @public

0 commit comments

Comments
 (0)