---
title: "Timeout | JavaScript maps SDK"
description: "Documentation for MapTiler SDK"
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Interface Timeout

This object is created internally and is returned from `setTimeout()` and `setInterval()`. It can be passed to either `clearTimeout()` or `clearInterval()` in order to cancel the scheduled actions.

By default, when a timer is scheduled using either `setTimeout()` or `setInterval()`, the Node.js event loop will continue running as long as the timer is active. Each of the `Timeout` objects returned by these functions export both `timeout.ref()` and `timeout.unref()` functions that can be used to control this default behavior.

interface Timeout {  
    [\_onTimeout](#_ontimeout-1)(...args: any\[\]): void;  
    ["\[dispose\]"](#dispose-1)(): void;  
    ["\[toPrimitive\]"](#toprimitive-1)(): number;  
    [close](#close-1)(): this;  
    [hasRef](#hasref-1)(): boolean;  
    [ref](#ref-1)(): this;  
    [refresh](#refresh-1)(): this;  
    [unref](#unref-1)(): this;  
}

#### Hierarchy ([View Summary](https://docs.maptiler.com/sdk-js/api-reference/hierarchy/#Externals.Timeout))

-   [RefCounted](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.RefCounted/)
-   [Disposable](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Disposable/)
-   [Timer](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/)
    -   Timeout

##### Index

### Methods[](#methods)

[\_onTimeout](#_ontimeout) [\[dispose\]](#dispose) [\[toPrimitive\]](#toprimitive) [close](#close) [hasRef](#hasref) [ref](#ref) [refresh](#refresh) [unref](#unref)

## Methods[](#methods-1)

### \_onTimeout[](#_ontimeout)

-   \_onTimeout(...args: any\[\]): void[](#_ontimeout-1)
    
    #### Parameters
    
    -   ...args: any\[\]
    
    #### Returns void
    

### \[dispose\][](#dispose)

-   "\[dispose\]"(): void[](#dispose-1)
    
    Cancels the timeout.
    
    #### Returns void
    
    #### Since[](#since)
    
    v20.5.0, v18.18.0
    
    Overrides [Disposable](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Disposable/).[\[dispose\]](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Disposable/#dispose)
    

### \[toPrimitive\][](#toprimitive)

-   "\[toPrimitive\]"(): number[](#toprimitive-1)
    
    Coerce a `Timeout` to a primitive. The primitive can be used to clear the `Timeout`. The primitive can only be used in the same thread where the timeout was created. Therefore, to use it across `worker_threads` it must first be passed to the correct thread. This allows enhanced compatibility with browser `setTimeout()` and `setInterval()` implementations.
    
    #### Returns number
    
    #### Since[](#since-1)
    
    v14.9.0, v12.19.0
    
    Overrides [Timer](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/).[\[toPrimitive\]](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/#toprimitive)
    

### close[](#close)

-   close(): this[](#close-1)
    
    Cancels the timeout.
    
    #### Returns this
    
    a reference to `timeout`
    
    #### Since[](#since-2)
    
    v0.9.1
    
    #### Legacy[](#legacy)
    
    Use `clearTimeout()` instead.
    

### hasRef[](#hasref)

-   hasRef(): boolean[](#hasref-1)
    
    If true, the `Timeout` object will keep the Node.js event loop active.
    
    #### Returns boolean
    
    #### Since[](#since-3)
    
    v11.0.0
    
    Overrides [Timer](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/).[hasRef](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/#hasref)
    

### ref[](#ref)

-   ref(): this[](#ref-1)
    
    When called, requests that the Node.js event loop _not_ exit so long as the `Timeout` is active. Calling `timeout.ref()` multiple times will have no effect.
    
    By default, all `Timeout` objects are "ref'ed", making it normally unnecessary to call `timeout.ref()` unless `timeout.unref()` had been called previously.
    
    #### Returns this
    
    a reference to `timeout`
    
    #### Since[](#since-4)
    
    v0.9.1
    
    Overrides [RefCounted](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.RefCounted/).[ref](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.RefCounted/#ref)
    

### refresh[](#refresh)

-   refresh(): this[](#refresh-1)
    
    Sets the timer's start time to the current time, and reschedules the timer to call its callback at the previously specified duration adjusted to the current time. This is useful for refreshing a timer without allocating a new JavaScript object.
    
    Using this on a timer that has already called its callback will reactivate the timer.
    
    #### Returns this
    
    a reference to `timeout`
    
    #### Since[](#since-5)
    
    v10.2.0
    
    Overrides [Timer](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/).[refresh](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Timer/#refresh)
    

### unref[](#unref)

-   unref(): this[](#unref-1)
    
    When called, the active `Timeout` object will not require the Node.js event loop to remain active. If there is no other activity keeping the event loop running, the process may exit before the `Timeout` object's callback is invoked. Calling `timeout.unref()` multiple times will have no effect.
    
    #### Returns this
    
    a reference to `timeout`
    
    #### Since[](#since-6)
    
    v0.9.1
    
    Overrides [RefCounted](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.RefCounted/).[unref](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.RefCounted/#unref)
