Skip to content

Instantly share code, notes, and snippets.

@attilaking
Created February 14, 2020 02:29
Show Gist options
  • Save attilaking/3d0882f2430dba010f9e977d2f7746ad to your computer and use it in GitHub Desktop.
Save attilaking/3d0882f2430dba010f9e977d2f7746ad to your computer and use it in GitHub Desktop.
[Javascript promise] How to do javascript promise #callback #promise
let p = new Promise((resolve, reject) => {
var imgData = 'data'; // this is always true
if (imgData) {
// This happens when the imgData returns true
resolve('Resolved');
}
else {
// This happens when imgData returns false;
reject('Rejected');
}
})
p.then((message) => {
// Success, so you can do soemthing here, that happens AFTER imgdata is declared
doc.addImage(imgData, 'JPEG', 20, 10, 50, 17)
}).catch((message) => {
// Error , so you can do something here to handle the error
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment