Timeout stops waiting for a call that takes too long. It aborts context.signal, so fetch and other signal-aware I/O stop too, and fails with TimeoutRejectedError.
Use it on every call to a remote dependency: without one, a hung connection holds a request, a socket and memory forever. A timeout only frees the caller. If your I/O ignores the signal (most SQL drivers), the work keeps running on the other side; see Databases.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
ResiliencePipelineBuilder adds Polly-style addRetry() / addTimeout() / … shortcuts on top, at the cost of
bundling every strategy. Strategies run in the order they are added: the first one added is the outermost.
Options are validated and strategy state (e.g. circuit breaker) is created on build().
The strategy computes the timeout (timeoutGenerator, else timeout) and starts a timer.
The callback receives a new signal linked to the caller’s: it aborts when the caller aborts or when the timer fires.
When the timer fires, the signal is aborted with the TimeoutRejectedError as its reason, onTimeout runs, and the execution fails with that error.
What happens to a callback that is still running depends on the mode:
Mode
When the time is up
Polly v8 equivalent
Aggressive (default)
Returns TimeoutRejectedErrorat once, even if the callback ignores the signal. The callback may keep running in the background; its result is discarded.
none (Polly’s pessimistic mode is close)
cooperative: true
Aborts the signal, then waits for the callback to settle, so no work outlives the timeout. A callback that ignores the signal delays the error until it finishes.
TimeoutStrategy
cooperative: true, keepLateResult: true
As cooperative, but if the callback still succeeds after the deadline, that result is returned instead of the error.
none
If the caller aborts (not the timer), the timeout strategy returns the callback’s outcome unchanged; no timeout error is raised and onTimeout is not called.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
addTimeout(5000), addTimeout('5s') or addTimeout({ timeout: '5s', onTimeout }).
addTimeout({
TimeoutOptions.timeout?: Duration |undefined
Default 30 s. Infinity disables the timeout.
timeout: '30s',
TimeoutOptions.cooperative?: boolean |undefined
false (default): give up as soon as the time is up, even if the callback ignores the signal.
true: abort the signal, then wait for the callback to finish (Polly v8 behaviour), so no work outlives the timeout.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
A timed-out attempt is retried by the default retry predicate: a timeout is a transient failure, not a rejection.
A pipeline executed inside another one inherits the outer signal, so an outer timeout also cancels nested calls. See Context, signals & deadline propagation.
timeoutGenerator picks the timeout per execution. It receives { context } and may be async. Returning 0, a negative number or Infinity runs that execution without a timeout.
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Polly-style builder with a shortcut for every strategy: addRetry(), addTimeout(), addCircuitBreaker(), …
Convenient, but it bundles every strategy. For the smallest browser bundle use PipelineBuilder with
retryStrategy(), timeoutStrategy(), … instead; the two are interchangeable.
The type parameters track which errors the pipeline can raise, for pipeline.settle() + Outcome.match().
Check for it with isTimeoutError(error); it works across duplicate copies of the package, unlike instanceof. Adding a timeout adds TimeoutRejectedError to the pipeline’s typed error union, so Outcome.match needs a TIMEOUT branch.
The same error object is the abort reason of the callback’s signal, so code deep inside the call can tell a timeout from a caller cancel:
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
The console module provides a simple debugging console that is similar to the
JavaScript console mechanism provided by web browsers.
The module exports two specific components:
A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
A global console instance configured to write to process.stdout and
process.stderr. The global console can be used without importing the node:console module.
Warning: The global console object's methods are neither consistently
synchronous like the browser APIs they resemble, nor are they consistently
asynchronous like all other Node.js streams. See the note on process I/O for
more information.
Example using the global console:
console.log('hello world');
// Prints: hello world, to stdout
console.log('hello %s', 'world');
// Prints: hello world, to stdout
console.error(newError('Whoops, something bad happened'));
// Prints error message and stack trace to stderr:
// Error: Whoops, something bad happened
// at [eval]:5:15
// at Script.runInThisContext (node:vm:132:18)
// at Object.runInThisContext (node:vm:309:38)
// at node:internal/process/execution:77:19
// at [eval]-wrapper:6:22
// at evalScript (node:internal/process/execution:76:60)
// at node:internal/main/eval_string:23:3
constname='Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Danger Will Robinson! Danger!, to stderr
Example using the Console class:
constout=getStreamSomehow();
consterr=getStreamSomehow();
constmyConsole=new console.Console(out, err);
myConsole.log('hello world');
// Prints: hello world, to out
myConsole.log('hello %s', 'world');
// Prints: hello world, to out
myConsole.error(newError('Whoops, something bad happened'));
// Prints: [Error: Whoops, something bad happened], to err