AdPreloader
import { AdPreloader } from 'nitro-ui-admob'
class AdPreloader<Ad extends { readonly expiresAt: number }>
Keeps one full-screen ad ready. After start it loads an ad, replaces it when it expires, retries failed loads with exponential backoff (5 seconds doubling up to 5 minutes), and loads the next ad when one is taken. Works with every full-screen class. Guide: preloading.
| Member | Description |
|---|---|
constructor(load, onLoadError?) | Creates a stopped preloader. |
start() | Starts loading. |
take() | Returns the ready ad and loads the next. |
isReady | Whether take() returns an ad. |
stop() | Stops loading and drops the ready ad. |
constructor
constructor(load: () => Promise<Ad>, onLoadError?: (error: unknown) => void)
load loads one ad, for example () => InterstitialAd.load(adUnitId). onLoadError is called with each failed load. Nothing loads until start.
start
start(): void
Starts loading. Idempotent.
take
take(): Ad | undefined
Returns the ready ad, or undefined if none is ready, and starts loading the next one.
isReady
get isReady(): boolean
Whether take returns an ad: one is loaded and its expiresAt has not passed.
stop
stop(): void
Stops loading and drops the ready ad. A load in flight finishes, but its ad is discarded. Call start() to resume.