/** * Asset loader configuration interface */ export interface AssetLoaderConfig { /** Limit on the number of concurrent loads */ maxConcurrentLoads?: number; /** Timeout duration (in milliseconds). Set to 0 or negative value to disable timeout */ timeout?: number; } /** * Helper type to infer the result object type from the promise object type */ type AwaitedObject = { [K in keyof T]: T[K] extends Promise ? U : T[K]; }; /** * Type-safe asset loader class * * @example * ```typescript * // Default configuration with 60 second timeout * const assetLoader = new AssetLoader(); * * // Configuration with custom settings * const customLoader = new AssetLoader({ * maxConcurrentLoads: 5, * timeout: 30000 // 30 seconds * }); * * // Disable timeout (wait indefinitely) * const noTimeoutLoader = new AssetLoader({ * timeout: 0 // or any negative value * }); * * // Load promises in object format * const assets = await assetLoader.load({ * environment: Rn.CubeTexture.fromUrl({ * baseUrl: '/path/to/environment', * mipmapLevelNumber: 1, * isNamePosNeg: true, * hdriFormat: Rn.HdriFormat.HDR_LINEAR, * }), * specular: Rn.CubeTexture.fromUrl({ * baseUrl: '/path/to/specular', * mipmapLevelNumber: 10, * isNamePosNeg: true, * hdriFormat: Rn.HdriFormat.RGBE_PNG, * }), * diffuse: Rn.CubeTexture.fromUrl({ * baseUrl: '/path/to/diffuse', * mipmapLevelNumber: 1, * isNamePosNeg: true, * hdriFormat: Rn.HdriFormat.RGBE_PNG, * }) * }); * * console.log(assets.environment); // CubeTexture * console.log(assets.specular); // CubeTexture * console.log(assets.diffuse); // CubeTexture * ``` */ export declare class AssetLoader { private config; private loadingQueue; private activeLoads; /** * Creates a new AssetLoader instance with the specified configuration. * * @param config - Configuration options for the asset loader * @param config.maxConcurrentLoads - Maximum number of concurrent loads (default: 3) * @param config.timeout - Timeout duration in milliseconds (default: 60000). Set to 0 or negative to disable * * @example * ```typescript * // Default configuration * const loader = new AssetLoader(); * * // Custom configuration * const customLoader = new AssetLoader({ * maxConcurrentLoads: 5, * timeout: 30000 * }); * ``` */ constructor(config?: AssetLoaderConfig); /** * Loads multiple promises organized as an object with named keys. * The result preserves the same structure with resolved values. * * @template T - Object type where values are promises * @param promiseObject - Object containing promises to be loaded * @returns Promise that resolves to an object with the same keys but resolved values * * @example * ```typescript * const assets = await loader.load({ * texture: loadTexture('path/to/texture.jpg'), * model: loadModel('path/to/model.gltf'), * audio: loadAudio('path/to/sound.mp3') * }); * * // Type-safe access to resolved values * console.log(assets.texture); // Texture * console.log(assets.model); // Model * console.log(assets.audio); // AudioBuffer * ``` */ load>>(promiseObject: T): Promise>; /** * Loads a single promise with queue management, timeout, and concurrency control. * * @template T - The type of value the promise resolves to * @param promise - The promise to be loaded * @returns Promise that resolves to the same value as the input promise * * @example * ```typescript * const texture = await loader.loadSingle(loadTexture('texture.jpg')); * const model = await loader.loadSingle(loadModel('model.gltf')); * ``` */ loadSingle(promise: Promise): Promise; /** * Loads a single promise with automatic retry using fallback factories. * If the first promise fails, it will try the next factory in order. * * @template T - The type of value the promise resolves to * @param promiseFactories - Array of factory functions that create promises, ordered by priority * @returns Promise that resolves to the value from the first successful factory * * @throws {Error} When no promise factories are provided * * @example * ```typescript * const texture = await loader.loadWithRetrySingle([ * () => loadTexture('high-quality.jpg'), // Try first * () => loadTexture('medium-quality.jpg'), // Fallback 1 * () => loadTexture('low-quality.jpg') // Fallback 2 * ]); * ``` */ loadWithRetrySingle(promiseFactories: Array<() => Promise>): Promise; /** * Loads multiple promises in bulk as an array. * Supports both homogeneous arrays and heterogeneous tuples with type safety. * * @template T - The type of values in the array or tuple * @param promises - Array or tuple of promises to be loaded * @returns Promise that resolves to an array or tuple of resolved values with preserved types * * @example * ```typescript * // Homogeneous array * const textures = await loader.loadArray([ * loadTexture('texture1.jpg'), * loadTexture('texture2.jpg'), * loadTexture('texture3.jpg') * ]); * * // Heterogeneous tuple with type safety * const [texture, model, audio] = await loader.loadArray([ * loadTexture('texture.jpg'), * loadModel('model.gltf'), * loadAudio('sound.mp3') * ] as const); * ``` */ loadArray(promises: Promise[]): Promise; loadArray(promises: readonly [...{ [K in keyof T]: Promise; }]): Promise; /** * Loads multiple promises with retry capabilities for each one. * Each promise has its own set of factory functions for retry attempts. * * @template T - The type of values the promises resolve to * @param promiseFactories - Array where each element is an array of factory functions for one promise * @returns Promise that resolves to an array of resolved values * * @example * ```typescript * const assets = await loader.loadWithRetryArray([ * [ * () => loadTexture('high-res.jpg'), * () => loadTexture('low-res.jpg') * ], * [ * () => loadModel('detailed.gltf'), * () => loadModel('simple.gltf') * ] * ]); * ``` */ loadWithRetryArray(promiseFactories: Array Promise>>): Promise; /** * Loads multiple promises with retry capabilities organized as an object. * Combines the structure of `load()` with the retry functionality of `loadWithRetryArray()`. * * @template T - Object type where values are promises * @param promiseFactories - Object where each value is an array of factory functions * @returns Promise that resolves to an object with the same keys but resolved values * * @example * ```typescript * const assets = await loader.loadWithRetry({ * texture: [ * () => loadTexture('high-res.jpg'), * () => loadTexture('low-res.jpg') * ], * model: [ * () => loadModel('detailed.gltf'), * () => loadModel('simple.gltf') * ] * }); * * console.log(assets.texture); // Texture (from successful factory) * console.log(assets.model); // Model (from successful factory) * ``` */ loadWithRetry>>(promiseFactories: { [K in keyof T]: Array<() => T[K]>; }): Promise>; /** * Internal method to load a single promise with multiple retry factories. * Handles the retry logic when the initial promise fails. * * @private * @template T - The type of value the promise resolves to * @param initialPromise - The first promise to attempt * @param retryFactories - Array of factory functions to use for retries * @returns Promise that resolves to the value from the first successful attempt */ private loadSingleWithMultipleRetries; /** * Internal method to process the loading queue. * Manages concurrency limits and handles retry logic for failed loads. * * @private * @returns Promise that resolves when queue processing is complete */ private processQueue; /** * Internal method to execute the actual loading process with timeout handling. * Races the promise against a timeout if configured. * * @private * @template T - The type of value the promise resolves to * @param request - The load request to execute * @returns Promise that resolves to the loaded value * * @throws {Error} When the load times out (if timeout is configured) */ private executeLoad; /** * Gets the current loading status including active and queued loads. * Useful for monitoring loading progress and debugging. * * @returns Object containing the number of active and queued loads * * @example * ```typescript * const status = loader.getLoadingStatus(); * console.log(`Active: ${status.active}, Queued: ${status.queued}`); * ``` */ getLoadingStatus(): { active: number; queued: number; }; /** * Waits until all currently active and queued loads are complete. * Useful for ensuring all assets are loaded before proceeding. * * @returns Promise that resolves when all loads are complete * * @example * ```typescript * // Start multiple loads * loader.loadSingle(loadTexture('texture.jpg')); * loader.loadSingle(loadModel('model.gltf')); * * // Wait for all to complete * await loader.waitForAllLoads(); * console.log('All assets loaded!'); * ``` */ waitForAllLoads(): Promise; } /** * Default asset loader instance with standard configuration. * Provides a convenient singleton for most use cases. * * @example * ```typescript * import { defaultAssetLoader } from './AssetLoader'; * * const assets = await defaultAssetLoader.load({ * texture: loadTexture('texture.jpg'), * model: loadModel('model.gltf') * }); * ``` */ export declare const defaultAssetLoader: AssetLoader; export {};