UNPKG

async-wait-until

Version:

Waits until the given predicate function returns a truthy value, then resolves

207 lines (191 loc) โ€ข 50.5 kB
<!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Documentation for async-wait-until v2.0.31</title><meta name="description" content="Documentation for Documentation for async-wait-until v2.0.31"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="index.html" class="title">Documentation for async-wait-until v2.0.31</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h1>Documentation for async-wait-until v2.0.31</h1></div><div class="tsd-panel tsd-typography"><h1 id="async-wait-until" class="tsd-anchor-link">async-wait-until<a href="#async-wait-until" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h1><p>A lightweight, zero-dependency library for waiting asynchronously until a specific condition is met. Works in any JavaScript environment that supports <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promises</a>, including older Node.js versions and browsers (with polyfills if necessary).</p> <p><img src="https://img.shields.io/npm/v/async-wait-until" alt="npm version"> <a href="https://npmjs.org/package/async-wait-until"><img src="https://img.shields.io/npm/dw/async-wait-until" alt="npm downloads"></a> <img src="https://img.shields.io/npm/l/async-wait-until" alt="MIT License"> <a href="https://qlty.sh/gh/devlato/projects/async-wait-until"><img src="https://qlty.sh/gh/devlato/projects/async-wait-until/maintainability.svg" alt="Maintainability"></a></p> <h2 id="โœจ-features" class="tsd-anchor-link">โœจ Features<a href="#โœจ-features" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul> <li>๐Ÿš€ <strong>Zero dependencies</strong> - Lightweight and fast</li> <li>๐Ÿ”ง <strong>TypeScript support</strong> - Full TypeScript definitions included</li> <li>๐ŸŒ <strong>Universal compatibility</strong> - Works in Node.js and browsers</li> <li>โšก <strong>Flexible configuration</strong> - Customizable timeouts and intervals</li> <li>๐ŸŽฏ <strong>Promise-based</strong> - Clean async/await syntax</li> <li>๐Ÿ“ฆ <strong>Multiple formats</strong> - UMD, ESM, and additional format bundles</li> <li>๐Ÿ›ก๏ธ <strong>Error handling</strong> - Built-in timeout error handling</li> </ul> <h2 id="๐Ÿ“š-table-of-contents" class="tsd-anchor-link">๐Ÿ“š Table of Contents<a href="#๐Ÿ“š-table-of-contents" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul> <li><a href="#-installation">Installation</a></li> <li><a href="#%EF%B8%8F-how-to-use">How to Use</a></li> <li><a href="#-api">API Reference</a></li> <li><a href="#-typescript-usage">TypeScript Usage</a></li> <li><a href="#-recipes">Recipes</a></li> <li><a href="#-browser-compatibility">Browser Compatibility</a></li> <li><a href="#-troubleshooting">Troubleshooting</a></li> <li><a href="#-development-and-testing">Development and Testing</a></li> <li><a href="#-links">Links</a></li> </ul> <h2 id="๐Ÿ“–-detailed-documentation" class="tsd-anchor-link">๐Ÿ“– Detailed Documentation<a href="#๐Ÿ“–-detailed-documentation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>For detailed documentation, visit <a href="https://devlato.github.io/async-wait-until/">https://devlato.github.io/async-wait-until/</a></p> <hr> <h2 id="๐Ÿš€-installation" class="tsd-anchor-link">๐Ÿš€ Installation<a href="#๐Ÿš€-installation" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Install using npm:</p> <pre><code class="sh"><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-2">install</span><span class="hl-1"> </span><span class="hl-2">async-wait-until</span> </code><button type="button">Copy</button></pre> <p>The library includes UMD and ESM bundles (plus additional formats), so you can use it in any environment.</p> <pre><code class="javascript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-5">// Example: Wait for an element to appear</span><br/><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">document</span><span class="hl-1">.</span><span class="hl-0">querySelector</span><span class="hl-1">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-1">) !== </span><span class="hl-6">null</span><span class="hl-1">);</span> </code><button type="button">Copy</button></pre> <hr> <h2 id="๐Ÿ› ๏ธ-how-to-use" class="tsd-anchor-link">๐Ÿ› ๏ธ How to Use<a href="#๐Ÿ› ๏ธ-how-to-use" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><h3 id="basic-example-wait-for-a-dom-element" class="tsd-anchor-link">Basic Example: Wait for a DOM Element<a href="#basic-example-wait-for-a-dom-element" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForElement</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-5">// Wait for an element with the ID &quot;target&quot; to appear</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">element</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">document</span><span class="hl-1">.</span><span class="hl-0">querySelector</span><span class="hl-1">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-1">), { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">5000</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">&#39;Element found:&#39;</span><span class="hl-1">, </span><span class="hl-4">element</span><span class="hl-1">);</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-0">waitForElement</span><span class="hl-1">();</span> </code><button type="button">Copy</button></pre> <h3 id="handling-timeouts" class="tsd-anchor-link">Handling Timeouts<a href="#handling-timeouts" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>If the condition is not met within the timeout, a <code>TimeoutError</code> is thrown.</p> <pre><code class="javascript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1">, </span><span class="hl-4">TimeoutError</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForElement</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">element</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">document</span><span class="hl-1">.</span><span class="hl-0">querySelector</span><span class="hl-1">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-1">), { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">5000</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">&#39;Element found:&#39;</span><span class="hl-1">, </span><span class="hl-4">element</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-3">catch</span><span class="hl-1"> (</span><span class="hl-4">error</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (</span><span class="hl-4">error</span><span class="hl-1"> </span><span class="hl-6">instanceof</span><span class="hl-1"> </span><span class="hl-9">TimeoutError</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-2">&#39;Timeout: Element not found&#39;</span><span class="hl-1">);</span><br/><span class="hl-1"> } </span><span class="hl-3">else</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-2">&#39;Unexpected error:&#39;</span><span class="hl-1">, </span><span class="hl-4">error</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-0">waitForElement</span><span class="hl-1">();</span> </code><button type="button">Copy</button></pre> <hr> <h2 id="๐Ÿ“š-api-reference" class="tsd-anchor-link">๐Ÿ“š API Reference<a href="#๐Ÿ“š-api-reference" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><h3 id="waituntilpredicate-options" class="tsd-anchor-link"><code>waitUntil(predicate, options)</code><a href="#waituntilpredicate-options" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Waits for the <code>predicate</code> function to return a truthy value and resolves with that value.</p> <p><strong>Parameters:</strong></p> <table> <thead> <tr> <th>Name</th> <th>Type</th> <th>Required</th> <th>Default</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>predicate</code></td> <td><code>Function</code></td> <td>โœ… Yes</td> <td>-</td> <td>A function that returns a truthy value (or a Promise for one).</td> </tr> <tr> <td><code>options.timeout</code></td> <td><code>number</code></td> <td>๐Ÿšซ No</td> <td><code>5000</code> ms</td> <td>Maximum wait time before throwing <code>TimeoutError</code>. Use <code>WAIT_FOREVER</code> for no timeout.</td> </tr> <tr> <td><code>options.intervalBetweenAttempts</code></td> <td><code>number</code></td> <td>๐Ÿšซ No</td> <td><code>50</code> ms</td> <td>Interval between predicate evaluations.</td> </tr> </tbody> </table> <h3 id="exported-constants" class="tsd-anchor-link">Exported Constants<a href="#exported-constants" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><table> <thead> <tr> <th>Name</th> <th>Value</th> <th>Description</th> </tr> </thead> <tbody> <tr> <td><code>WAIT_FOREVER</code></td> <td><code>โˆž</code></td> <td>Use for infinite timeout (no time limit).</td> </tr> <tr> <td><code>DEFAULT_TIMEOUT_IN_MS</code></td> <td><code>5000</code></td> <td>Default timeout duration in milliseconds.</td> </tr> <tr> <td><code>DEFAULT_INTERVAL_BETWEEN_ATTEMPTS_IN_MS</code></td> <td><code>50</code></td> <td>Default interval between attempts in milliseconds.</td> </tr> </tbody> </table> <h3 id="exported-classes" class="tsd-anchor-link">Exported Classes<a href="#exported-classes" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul> <li><strong><code>TimeoutError</code></strong> - Error thrown when timeout is reached before condition is met.</li> </ul> <hr> <h2 id="๐Ÿ”ง-typescript-usage" class="tsd-anchor-link">๐Ÿ”ง TypeScript Usage<a href="#๐Ÿ”ง-typescript-usage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>This library is written in TypeScript and includes full type definitions. Here are some TypeScript-specific examples:</p> <h3 id="basic-typescript-usage" class="tsd-anchor-link">Basic TypeScript Usage<a href="#basic-typescript-usage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1">, </span><span class="hl-4">TimeoutError</span><span class="hl-1">, </span><span class="hl-4">WAIT_FOREVER</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-5">// The return type is automatically inferred</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">element</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">document</span><span class="hl-1">.</span><span class="hl-0">querySelector</span><span class="hl-1">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-1">));</span><br/><span class="hl-5">// element is typed as Element | null</span><br/><br/><span class="hl-5">// With custom timeout and interval</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">result</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(</span><br/><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-0">someAsyncCondition</span><span class="hl-1">(),</span><br/><span class="hl-1"> { </span><br/><span class="hl-1"> </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">10000</span><span class="hl-1">, </span><br/><span class="hl-1"> </span><span class="hl-4">intervalBetweenAttempts:</span><span class="hl-1"> </span><span class="hl-8">100</span><span class="hl-1"> </span><br/><span class="hl-1"> }</span><br/><span class="hl-1">);</span> </code><button type="button">Copy</button></pre> <h3 id="using-with-async-predicates" class="tsd-anchor-link">Using with Async Predicates<a href="#using-with-async-predicates" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-5">// Async predicate example</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">checkApiStatus</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> (): </span><span class="hl-9">Promise</span><span class="hl-1">&lt;</span><span class="hl-9">boolean</span><span class="hl-1">&gt; </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">response</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">fetch</span><span class="hl-1">(</span><span class="hl-2">&#39;/api/health&#39;</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">response</span><span class="hl-1">.</span><span class="hl-4">ok</span><span class="hl-1">;</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-3">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(</span><span class="hl-4">checkApiStatus</span><span class="hl-1">, { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">30000</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">&#39;API is ready!&#39;</span><span class="hl-1">);</span><br/><span class="hl-1">} </span><span class="hl-3">catch</span><span class="hl-1"> (</span><span class="hl-4">error</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (</span><span class="hl-4">error</span><span class="hl-1"> </span><span class="hl-6">instanceof</span><span class="hl-1"> </span><span class="hl-9">TimeoutError</span><span class="hl-1">) {</span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">error</span><span class="hl-1">(</span><span class="hl-2">&#39;API failed to become ready within 30 seconds&#39;</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">}</span> </code><button type="button">Copy</button></pre> <h3 id="type-safe-options" class="tsd-anchor-link">Type-Safe Options<a href="#type-safe-options" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">Options</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">customOptions</span><span class="hl-1">: </span><span class="hl-9">Options</span><span class="hl-1"> = {</span><br/><span class="hl-1"> </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">15000</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">intervalBetweenAttempts:</span><span class="hl-1"> </span><span class="hl-8">200</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-0">someCondition</span><span class="hl-1">(), </span><span class="hl-4">customOptions</span><span class="hl-1">);</span> </code><button type="button">Copy</button></pre> <hr> <h2 id="๐Ÿ’ก-recipes" class="tsd-anchor-link">๐Ÿ’ก Recipes<a href="#๐Ÿ’ก-recipes" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><h3 id="wait-indefinitely" class="tsd-anchor-link">Wait Indefinitely<a href="#wait-indefinitely" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Use <code>WAIT_FOREVER</code> to wait without a timeout:</p> <pre><code class="javascript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1">, </span><span class="hl-4">WAIT_FOREVER</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">someCondition</span><span class="hl-1">, { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-7">WAIT_FOREVER</span><span class="hl-1"> });</span> </code><button type="button">Copy</button></pre> <h3 id="adjust-retry-interval" class="tsd-anchor-link">Adjust Retry Interval<a href="#adjust-retry-interval" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p>Change how often the predicate is evaluated:</p> <pre><code class="javascript"><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">someCondition</span><span class="hl-1">, { </span><span class="hl-4">intervalBetweenAttempts:</span><span class="hl-1"> </span><span class="hl-8">1000</span><span class="hl-1"> }); </span><span class="hl-5">// Check every 1 second</span> </code><button type="button">Copy</button></pre> <h3 id="wait-for-api-response" class="tsd-anchor-link">Wait for API Response<a href="#wait-for-api-response" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForApi</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">response</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(</span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">res</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">fetch</span><span class="hl-1">(</span><span class="hl-2">&#39;/api/status&#39;</span><span class="hl-1">);</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">res</span><span class="hl-1">.</span><span class="hl-4">ok</span><span class="hl-1"> ? </span><span class="hl-4">res</span><span class="hl-1"> : </span><span class="hl-6">null</span><span class="hl-1">;</span><br/><span class="hl-1"> } </span><span class="hl-3">catch</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-6">null</span><span class="hl-1">; </span><span class="hl-5">// Keep trying on network errors</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> }, { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">30000</span><span class="hl-1">, </span><span class="hl-4">intervalBetweenAttempts:</span><span class="hl-1"> </span><span class="hl-8">1000</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">response</span><span class="hl-1">.</span><span class="hl-0">json</span><span class="hl-1">();</span><br/><span class="hl-1">};</span> </code><button type="button">Copy</button></pre> <h3 id="wait-for-file-system-changes-nodejs" class="tsd-anchor-link">Wait for File System Changes (Node.js)<a href="#wait-for-file-system-changes-nodejs" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-3">import</span><span class="hl-1"> </span><span class="hl-4">fs</span><span class="hl-1"> </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;fs&#39;</span><span class="hl-1">;</span><br/><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-5">// Wait for a file to be created</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">filePath</span><span class="hl-1"> = </span><span class="hl-2">&#39;./important-file.txt&#39;</span><span class="hl-1">;</span><br/><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> </span><span class="hl-4">fs</span><span class="hl-1">.</span><span class="hl-0">existsSync</span><span class="hl-1">(</span><span class="hl-4">filePath</span><span class="hl-1">), { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">10000</span><span class="hl-1"> });</span><br/><br/><span class="hl-5">// Wait for file to have content</span><br/><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">if</span><span class="hl-1"> (</span><span class="hl-4">fs</span><span class="hl-1">.</span><span class="hl-0">existsSync</span><span class="hl-1">(</span><span class="hl-4">filePath</span><span class="hl-1">)) {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">fs</span><span class="hl-1">.</span><span class="hl-0">readFileSync</span><span class="hl-1">(</span><span class="hl-4">filePath</span><span class="hl-1">, </span><span class="hl-2">&#39;utf8&#39;</span><span class="hl-1">).</span><span class="hl-0">trim</span><span class="hl-1">().</span><span class="hl-4">length</span><span class="hl-1"> &gt; </span><span class="hl-8">0</span><span class="hl-1">;</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-6">false</span><span class="hl-1">;</span><br/><span class="hl-1">});</span> </code><button type="button">Copy</button></pre> <h3 id="wait-for-database-connection" class="tsd-anchor-link">Wait for Database Connection<a href="#wait-for-database-connection" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForDatabase</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> (</span><span class="hl-4">db</span><span class="hl-1">) </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(</span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">try</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-4">db</span><span class="hl-1">.</span><span class="hl-0">ping</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-6">true</span><span class="hl-1">;</span><br/><span class="hl-1"> } </span><span class="hl-3">catch</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-6">false</span><span class="hl-1">;</span><br/><span class="hl-1"> }</span><br/><span class="hl-1"> }, { </span><span class="hl-4">timeout:</span><span class="hl-1"> </span><span class="hl-8">60000</span><span class="hl-1">, </span><span class="hl-4">intervalBetweenAttempts:</span><span class="hl-1"> </span><span class="hl-8">2000</span><span class="hl-1"> });</span><br/><span class="hl-1"> </span><br/><span class="hl-1"> </span><span class="hl-4">console</span><span class="hl-1">.</span><span class="hl-0">log</span><span class="hl-1">(</span><span class="hl-2">&#39;Database is ready!&#39;</span><span class="hl-1">);</span><br/><span class="hl-1">};</span> </code><button type="button">Copy</button></pre> <h3 id="wait-with-custom-conditions" class="tsd-anchor-link">Wait with Custom Conditions<a href="#wait-with-custom-conditions" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="javascript"><span class="hl-5">// Wait for multiple conditions</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForComplexCondition</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(() </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">user</span><span class="hl-1"> = </span><span class="hl-0">getCurrentUser</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">permissions</span><span class="hl-1"> = </span><span class="hl-0">getPermissions</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">apiReady</span><span class="hl-1"> = </span><span class="hl-0">isApiReady</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><br/><span class="hl-1"> </span><span class="hl-5">// All conditions must be true</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">user</span><span class="hl-1"> &amp;&amp; </span><span class="hl-4">permissions</span><span class="hl-1">.</span><span class="hl-4">length</span><span class="hl-1"> &gt; </span><span class="hl-8">0</span><span class="hl-1"> &amp;&amp; </span><span class="hl-4">apiReady</span><span class="hl-1">;</span><br/><span class="hl-1"> });</span><br/><span class="hl-1">};</span><br/><br/><span class="hl-5">// Wait for specific value ranges</span><br/><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-0">waitForTemperature</span><span class="hl-1"> = </span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-0">waitUntil</span><span class="hl-1">(</span><span class="hl-6">async</span><span class="hl-1"> () </span><span class="hl-6">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-6">const</span><span class="hl-1"> </span><span class="hl-7">temp</span><span class="hl-1"> = </span><span class="hl-3">await</span><span class="hl-1"> </span><span class="hl-0">getSensorTemperature</span><span class="hl-1">();</span><br/><span class="hl-1"> </span><span class="hl-3">return</span><span class="hl-1"> </span><span class="hl-4">temp</span><span class="hl-1"> &gt;= </span><span class="hl-8">20</span><span class="hl-1"> &amp;&amp; </span><span class="hl-4">temp</span><span class="hl-1"> &lt;= </span><span class="hl-8">25</span><span class="hl-1"> ? </span><span class="hl-4">temp</span><span class="hl-1"> : </span><span class="hl-6">null</span><span class="hl-1">;</span><br/><span class="hl-1"> });</span><br/><span class="hl-1">};</span> </code><button type="button">Copy</button></pre> <hr> <h2 id="๐ŸŒ-browser-compatibility" class="tsd-anchor-link">๐ŸŒ Browser Compatibility<a href="#๐ŸŒ-browser-compatibility" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>This library works in any JavaScript environment that supports Promises:</p> <p><strong>Node.js:</strong> โœ… Version 0.14.0 and above<br> <strong>Modern Browsers:</strong> โœ… Chrome 32+, Firefox 29+, Safari 8+, Edge 12+<br> <strong>Legacy Browsers:</strong> โœ… With Promise polyfill (e.g., es6-promise)</p> <h3 id="cdn-usage" class="tsd-anchor-link">CDN Usage<a href="#cdn-usage" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="html"><span class="hl-5">&lt;!-- UMD bundle via CDN --&gt;</span><br/><span class="hl-10">&lt;</span><span class="hl-11">script</span><span class="hl-12"> </span><span class="hl-13">src</span><span class="hl-12">=</span><span class="hl-14">&quot;https://unpkg.com/async-wait-until@latest/dist/index.js&quot;</span><span class="hl-10">&gt;&lt;/</span><span class="hl-11">script</span><span class="hl-10">&gt;</span><br/><span class="hl-10">&lt;</span><span class="hl-11">script</span><span class="hl-10">&gt;</span><br/><span class="hl-12"> </span><span class="hl-5">// Available as global variable</span><br/><span class="hl-12"> </span><span class="hl-4">asyncWaitUntil</span><span class="hl-12">.</span><span class="hl-0">waitUntil</span><span class="hl-12">(() </span><span class="hl-6">=&gt;</span><span class="hl-12"> </span><span class="hl-4">document</span><span class="hl-12">.</span><span class="hl-0">querySelector</span><span class="hl-12">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-12">))</span><br/><span class="hl-12"> .</span><span class="hl-0">then</span><span class="hl-12">(</span><span class="hl-4">element</span><span class="hl-12"> </span><span class="hl-6">=&gt;</span><span class="hl-12"> </span><span class="hl-4">console</span><span class="hl-12">.</span><span class="hl-0">log</span><span class="hl-12">(</span><span class="hl-2">&#39;Found:&#39;</span><span class="hl-12">, </span><span class="hl-4">element</span><span class="hl-12">));</span><br/><span class="hl-10">&lt;/</span><span class="hl-11">script</span><span class="hl-10">&gt;</span> </code><button type="button">Copy</button></pre> <h3 id="es-modules-in-browser" class="tsd-anchor-link">ES Modules in Browser<a href="#es-modules-in-browser" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><pre><code class="html"><span class="hl-10">&lt;</span><span class="hl-11">script</span><span class="hl-12"> </span><span class="hl-13">type</span><span class="hl-12">=</span><span class="hl-14">&quot;module&quot;</span><span class="hl-10">&gt;</span><br/><span class="hl-12"> </span><span class="hl-3">import</span><span class="hl-12"> { </span><span class="hl-4">waitUntil</span><span class="hl-12"> } </span><span class="hl-3">from</span><span class="hl-12"> </span><span class="hl-2">&#39;https://unpkg.com/async-wait-until@latest/dist/index.esm.js&#39;</span><span class="hl-12">;</span><br/><span class="hl-12"> </span><br/><span class="hl-12"> </span><span class="hl-6">const</span><span class="hl-12"> </span><span class="hl-7">element</span><span class="hl-12"> </span><span class="hl-1">=</span><span class="hl-12"> </span><span class="hl-3">await</span><span class="hl-12"> </span><span class="hl-0">waitUntil</span><span class="hl-12">(() </span><span class="hl-6">=&gt;</span><span class="hl-12"> </span><span class="hl-4">document</span><span class="hl-12">.</span><span class="hl-0">querySelector</span><span class="hl-12">(</span><span class="hl-2">&#39;#target&#39;</span><span class="hl-12">));</span><br/><span class="hl-12"> </span><span class="hl-4">console</span><span class="hl-12">.</span><span class="hl-0">log</span><span class="hl-12">(</span><span class="hl-2">&#39;Found:&#39;</span><span class="hl-12">, </span><span class="hl-4">element</span><span class="hl-12">);</span><br/><span class="hl-10">&lt;/</span><span class="hl-11">script</span><span class="hl-10">&gt;</span> </code><button type="button">Copy</button></pre> <hr> <h2 id="๐Ÿ”-troubleshooting" class="tsd-anchor-link">๐Ÿ” Troubleshooting<a href="#๐Ÿ”-troubleshooting" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><h3 id="common-issues" class="tsd-anchor-link">Common Issues<a href="#common-issues" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><p><strong>Q: My predicate never resolves, what's wrong?</strong><br> A: Make sure your predicate function returns a truthy value when the condition is met. Common mistakes:</p> <ul> <li>Forgetting to return a value: <code>() =&gt; { someCheck(); }</code> โŒ</li> <li>Correct: <code>() =&gt; { return someCheck(); }</code> โœ… or <code>() =&gt; someCheck()</code> โœ…</li> </ul> <p><strong>Q: I'm getting unexpected timeout errors</strong><br> A: Check that:</p> <ul> <li>Your timeout is long enough for the condition to be met</li> <li>Your predicate function doesn't throw unhandled errors</li> <li>Network requests in predicates have proper error handling</li> </ul> <p><strong>Q: The function seems to run forever</strong><br> A: This happens when:</p> <ul> <li>Using <code>WAIT_FOREVER</code> without proper condition logic</li> <li>Predicate always returns falsy values</li> <li>Add logging to debug: <code>() =&gt; { const result = myCheck(); console.log(result); return result; }</code></li> </ul> <p><strong>Q: TypeScript compilation errors</strong><br> A: Ensure you're importing types correctly:</p> <pre><code class="typescript"><span class="hl-3">import</span><span class="hl-1"> { </span><span class="hl-4">waitUntil</span><span class="hl-1">, </span><span class="hl-4">Options</span><span class="hl-1">, </span><span class="hl-4">TimeoutError</span><span class="hl-1"> } </span><span class="hl-3">from</span><span class="hl-1"> </span><span class="hl-2">&#39;async-wait-until&#39;</span><span class="hl-1">;</span> </code><button type="button">Copy</button></pre> <h3 id="performance-tips" class="tsd-anchor-link">Performance Tips<a href="#performance-tips" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h3><ul> <li>Use reasonable intervals (50-1000ms) to balance responsiveness and CPU usage</li> <li>For expensive operations, increase the interval: <code>{ intervalBetweenAttempts: 1000 }</code></li> <li>Implement proper error handling in async predicates to avoid unnecessary retries</li> <li>Consider using <code>WAIT_FOREVER</code> with external cancellation for long-running waits</li> </ul> <hr> <h2 id="๐Ÿงช-development-and-testing" class="tsd-anchor-link">๐Ÿงช Development and Testing<a href="#๐Ÿงช-development-and-testing" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><p>Contributions are welcome! To contribute:</p> <ol> <li>Fork and clone the repository.</li> <li>Install dependencies: <code>npm install</code>.</li> <li>Use the following commands:</li> </ol> <ul> <li><strong>Run Tests:</strong> <code>npm test</code></li> <li><strong>Lint Code:</strong> <code>npm run lint</code></li> <li><strong>Format Code:</strong> <code>npm run format</code></li> <li><strong>Build Library:</strong> <code>npm run build</code></li> <li><strong>Generate Docs:</strong> <code>npm run docs</code></li> </ul> <hr> <h2 id="๐Ÿ“-links" class="tsd-anchor-link">๐Ÿ“ Links<a href="#๐Ÿ“-links" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></h2><ul> <li><a href="media/LICENSE">License</a></li> <li><a href="https://devlato.github.io/async-wait-until/">Detailed Documentation</a></li> <li><a href="media/CHANGELOG.md">Changelog</a> - Track version updates and changes</li> <li><a href="media/CONTRIBUTING.md">Contributing Guidelines</a> - How to contribute to the project</li> <li><a href="media/CODE_OF_CONDUCT.md">Code of Conduct</a> - Community standards and expectations</li> </ul> </div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#async-wait-until"><span>async-<wbr/>wait-<wbr/>until</span></a><ul><li><a href="#โœจ-features"><span>โœจ <wbr/>Features</span></a></li><li><a href="#๐Ÿ“š-table-of-contents"><span>๐Ÿ“š <wbr/>Table of <wbr/>Contents</span></a></li><li><a href="#๐Ÿ“–-detailed-documentation"><span>๐Ÿ“– <wbr/>Detailed <wbr/>Documentation</span></a></li><li><a href="#๐Ÿš€-installation"><span>๐Ÿš€ <wbr/>Installation</span></a></li><li><a href="#๐Ÿ› ๏ธ-how-to-use"><span>๐Ÿ› ๏ธ <wbr/>How to <wbr/>Use</span></a></li><li><ul><li><a href="#basic-example-wait-for-a-dom-element"><span>Basic <wbr/>Example: <wbr/>Wait for a DOM <wbr/>Element</span></a></li><li><a href="#handling-timeouts"><span>Handling <wbr/>Timeouts</span></a></li></ul></li><li><a href="#๐Ÿ“š-api-reference"><span>๐Ÿ“š API <wbr/>Reference</span></a></li><li><ul><li><a href="#waituntilpredicate-options"><span>wait<wbr/>Until(predicate, options)</span></a></li><li><a href="#exported-constants"><span>Exported <wbr/>Constants</span></a></li><li><a href="#exported-classes"><span>Exported <wbr/>Classes</span></a></li></ul></li><li><a href="#๐Ÿ”ง-typescript-usage"><span>๐Ÿ”ง <wbr/>Type<wbr/>Script <wbr/>Usage</span></a></li><li><ul><li><a href="#basic-typescript-usage"><span>Basic <wbr/>Type<wbr/>Script <wbr/>Usage</span></a></li><li><a href="#using-with-async-predicates"><span>Using with <wbr/>Async <wbr/>Predicates</span></a></li><li><a href="#type-safe-options"><span>Type-<wbr/>Safe <wbr/>Options</span></a></li></ul></li><li><a href="#๐Ÿ’ก-recipes"><span>๐Ÿ’ก <wbr/>Recipes</span></a></li><li><ul><li><a href="#wait-indefinitely"><span>Wait <wbr/>Indefinitely</span></a></li><li><a href="#adjust-retry-interval"><span>Adjust <wbr/>Retry <wbr/>Interval</span></a></li><li><a href="#wait-for-api-response"><span>Wait for API <wbr/>Response</span></a></li><li><a href="#wait-for-file-system-changes-nodejs"><span>Wait for <wbr/>File <wbr/>System <wbr/>Changes (<wbr/>Node.js)</span></a></li><li><a href="#wait-for-database-connection"><span>Wait for <wbr/>Database <wbr/>Connection</span></a></li><li><a href="#wait-with-custom-conditions"><span>Wait with <wbr/>Custom <wbr/>Conditions</span></a></li></ul></li><li><a href="#๐ŸŒ-browser-compatibility"><span>๐ŸŒ <wbr/>Browser <wbr/>Compatibility</span></a></li><li><ul><li><a href="#cdn-usage"><span>CDN <wbr/>Usage</span></a></li><li><a href="#es-modules-in-browser"><span>ES <wbr/>Modules in <wbr/>Browser</span></a></li></ul></li><li><a href="#๐Ÿ”-troubleshooting"><span>๐Ÿ” <wbr/>Troubleshooting</span></a></li><li><ul><li><a href="#common-issues"><span>Common <wbr/>Issues</span></a></li><li><a href="#performance-tips"><span>Performance <wbr/>Tips</span></a></li></ul></li><li><a href="#๐Ÿงช-development-and-testing"><span>๐Ÿงช <wbr/>Development and <wbr/>Testing</span></a></li><li><a href="#๐Ÿ“-links"><span>๐Ÿ“ <wbr/>Links</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.