diff --git a/fetch-timeout/index.ts b/fetch-timeout/index.ts new file mode 100644 index 0000000..685db90 --- /dev/null +++ b/fetch-timeout/index.ts @@ -0,0 +1,39 @@ +export function getDescription() { + return { + description: "Fetch With Custom Timeout", + input: [ + { + id: "endpoint", + displayName: "Endpoint", + description: "URL of the endpoint to fetch data from.", + type: "Connector", + required: true, + }, + { + id: "abortRequestTimeoutInMs", + displayName: "Abort Request Timeout in milliseconds", + description: "Abort Request Timeout in milliseconds.", + type: "Number", + required: true, + }, + ], + output: [], + } as const satisfies ScriptDescription; +} + +export async function execute(context: Context): Promise { + const endpoint = context.parameters.endpoint as string; + const abortRequestTimeoutInMs = context.parameters.abortRequestTimeoutInMs as number; + + const abortController = new AbortController(); + const options = { signal: abortController.signal }; + + setTimeout(() => { + abortController.abort(); + console.log("Abort called"); + }, abortRequestTimeoutInMs); + + const response = await fetch(endpoint, options); + const responseData = await response.text(); + console.debug(responseData); +} diff --git a/fetch-timeout/package.json b/fetch-timeout/package.json new file mode 100644 index 0000000..0025bb3 --- /dev/null +++ b/fetch-timeout/package.json @@ -0,0 +1,8 @@ +{ + "name": "fetch-with-custom-timeout", + "displayName": "Fetch With Custom Timeout", + "description": "Provides an example of a fetch with custom timeout. Requires a Web endpoint type connector. WARNING: you have to either read the response body or close the connection because of the limitation of 6 outbound connections.", + "fromVersion": "23.08", + "toVersion": null, + "private": true +}