Skip to content

Timeout

Executes a callback with a server-side time limit.

1
myScript.Timeout(fn: () => ( T | Promise<T> ), milliseconds: number):( T | null )

Parameters

() => ( T | Promise ) fn
    The callback to execute. Server workflow scripts may return a value or a promise.

number milliseconds
    The positive time limit in milliseconds.

Returns

The callback result on success; otherwise null.

Remarks

Server workflow scripts only. null represents both a timeout and a callback failure because the server captures either outcome. Use a result value that can be distinguished from null when that distinction matters. This method does not provide transaction isolation; combine it with Isolated() only when an independent transaction is intentionally required.

Examples

Limit the time of an external call

1
2
3
4
5
6
7
var rates = Script.Timeout(function () {
    return $Rest.Create('https://api.example.com').Request('rates').Get().ToJson();
}, 5000);

if (rates === null) {
    throw new Error('The exchange rate service did not respond in time.');
}