the following is part of my codebase:
const clonePromises = cloneServices?.getAds().map((ad: IAds) => {
switch(ad.type) {
case 'tree':
return api.cloneA(ad.id);
case 'creativegroup':
return api.cloneB(ad.id);
case 'creative':
return api.cloneC(ad.name, ad.id, ad.hasVariations);
case 'trackerresource':
return cloneTracker(ad);
case 'folder':
return api.cloneFolder(ad.id).then(null, (err) => {
let error = 'Unknown error';
try {
error =
JSON.parse(err.responseText)?.message || JSON.parse(err.responseText)?.errors?.message;
} catch {
//noop
}
return new $.Deferred()
.resolve({
folderError: error,
})
.promise();
});
default:
// Unable to clone
}
}
);
Promise.all(clonePromises)
.then(async (responses) => {
return responses;
})
.then((responses) => {
console.log('show this')
}
This is part of the a function that is triggered by a button handleClick. Promise.all
is expected to be triggered after the $.Deferred()
operation is triggered and I should see a message called show this
in console. Currently, it's working fine, but I want to replace the following jQuery Deferred to promise.
return new $.Deferred()
.resolve({
folderError: error,
})
.promise();
I tried the following, but Promise.all
operation is not displaying show this
in console.
return new Promise((resolve)=>{
resolve({
folderError: error,
})
})