refactor: fix promises-version.
This commit is contained in:
parent
2ca737cead
commit
e19eb4693e
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue