diff --git a/libs/client/package.json b/libs/client/package.json
index e7a4831..4601abb 100644
--- a/libs/client/package.json
+++ b/libs/client/package.json
@@ -1,7 +1,7 @@
{
"name": "@fal-ai/serverless-client",
"description": "The fal serverless JS/TS client",
- "version": "0.14.0-alpha.1",
+ "version": "0.14.0-alpha.2",
"license": "MIT",
"repository": {
"type": "git",
diff --git a/libs/client/src/function.ts b/libs/client/src/function.ts
index e74e8d9..aa306a0 100644
--- a/libs/client/src/function.ts
+++ b/libs/client/src/function.ts
@@ -123,6 +123,8 @@ export async function run(
return send(id, options);
}
+type TimeoutId = ReturnType;
+
const DEFAULT_POLL_INTERVAL = 500;
/**
@@ -140,6 +142,16 @@ export async function subscribe(
if (options.onEnqueue) {
options.onEnqueue(requestId);
}
+ const timeout = options.timeout;
+ let timeoutId: TimeoutId = undefined;
+ if (timeout) {
+ timeoutId = setTimeout(() => {
+ queue.cancel(id, { requestId }).catch(console.warn);
+ throw new Error(
+ `Client timed out waiting for the request to complete after ${timeout}ms`
+ );
+ }, timeout);
+ }
if (options.mode === 'streaming') {
const status = await queue.streamStatus(id, {
requestId,
@@ -160,6 +172,9 @@ export async function subscribe(
}
});
await status.done();
+ if (timeoutId) {
+ clearTimeout(timeoutId);
+ }
return queue.result