---
title: "addAbortListener | 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.

# Function addAbortListener

-   addAbortListener(  
        signal: AbortSignal,  
        resource: (event: Event) \=> void,  
    ): [Disposable](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Disposable/)[](#addabortlistener)
    
    Listens once to the `abort` event on the provided `signal`.
    
    Listening to the `abort` event on abort signals is unsafe and may lead to resource leaks since another third party with the signal can call `e.stopImmediatePropagation()`. Unfortunately Node.js cannot change this since it would violate the web standard. Additionally, the original API makes it easy to forget to remove listeners.
    
    This API allows safely using `AbortSignal`s in Node.js APIs by solving these two issues by listening to the event such that `stopImmediatePropagation` does not prevent the listener from running.
    
    Returns a disposable so that it may be unsubscribed from more easily.
    
    ```typescript
    import { addAbortListener } from 'node:events';
    
    function example(signal) {
      let disposable;
      try {
        signal.addEventListener('abort', (e) => e.stopImmediatePropagation());
        disposable = addAbortListener(signal, (e) => {
          // Do something when signal is aborted.
        });
      } finally {
        disposable?.[Symbol.dispose]();
      }
    }
    ```
    
    #### Parameters
    
    -   signal: AbortSignal
    -   resource: (event: Event) \=> void
    
    #### Returns [Disposable](https://docs.maptiler.com/sdk-js/api-reference/interfaces/Externals.Disposable/)
    
    Disposable that removes the `abort` listener.
    
    #### Since[](#since)
    
    v20.5.0
