refactor: fix promises-version.

This commit is contained in:
Rintim 2024-05-12 02:31:40 +08:00
parent 2ca737cead
commit e19eb4693e
No known key found for this signature in database
GPG Key ID: BE9E1EA615BACFCF
1 changed files with 18 additions and 1 deletions

View File

@ -72,6 +72,23 @@ export class LibInitPromises {
* @returns {Promise<URL>}
*/
parseResourceAddress(link, defaultHandle = null, forceLoadAsDataUrl = false) {
return lib.init.parseResourceAddress(link, defaultHandle, forceLoadAsDataUrl);
if (!forceLoadAsDataUrl) return Promise.resolve(lib.init.parseResourceAddress(link, defaultHandle));
let { promise, resolve } = Promise.withResolvers();
lib.init.parseResourceAddress(link, defaultHandle, result => resolve(result));
return promise;
}
/**
* @async
* @param {string | URL} link - 需要解析的路径
* @param {((item: string) => string) | null} [defaultHandle] - 在给定路径不符合可用情况或基于无名杀相关默认情况处理路径的函数返回的路径应是相对于根目录的相对路径默认为`null`当且仅当无法解析成`URL`时会调用该回调
* @returns {Promise<[origin: URL, data: URL]>}
*/
async parseResourceAddressExt(link, defaultHandle = null) {
let { promise, resolve } = Promise.withResolvers();
let origin = lib.init.parseResourceAddress(link, defaultHandle, result => resolve(result));
return [origin, await promise];
}
}