Created
February 14, 2020 02:29
-
-
Save attilaking/3d0882f2430dba010f9e977d2f7746ad to your computer and use it in GitHub Desktop.
[Javascript promise] How to do javascript promise #callback #promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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