I am looking to create a custom promise
and have attempted the code below. My challenge lies in retrieving the value of recommendationCacheUrls
after the inner promise, specifically the fileTransfer.download
promise, has resolved.
setNewCacheUrls(providedUrls: any, nativeURL: string): Promise<any> {
return new Promise((resolve, reject) => {
let recommendationCacheUrls = [];
_.forEach(providedUrls, (url) => {
const fileTransfer: TransferObject = this.transfer.create();
fileTransfer.download(url.url, nativeURL + url.name).then((entry) => {
recommendationCacheUrls.push({ name: url.name, url: entry.toURL() });
}, (error) => {
console.error('error: ' + error);
});
});
resolve(recommendationCacheUrls);
});
}