Skip to content

Instantly share code, notes, and snippets.

@rajaramtt
Last active July 22, 2021 15:30
Show Gist options
  • Save rajaramtt/080da6c5faab34c6e658c3331d9df119 to your computer and use it in GitHub Desktop.
Save rajaramtt/080da6c5faab34c6e658c3331d9df119 to your computer and use it in GitHub Desktop.
Promise Code in JS
testFun(): void {
this.testPromise(identity).then(data => {
}).catch(function (e) {
console.log(e);
});
}
private testPromise(identity): Promise<any> {
const outerThis = this;
return new Promise(resolve => {
resolve();
});
}
function loadData() {
return new Promise(function(resolve, reject) {
setTimeout(() => {
alert('hi');
resolve("success")
});
});
}
loadData().then(
result => {
alert('hello')
},
error => {
alert(error)
});
/* Call Back */
function loadData(callback) {
setTimeout(function() {
alert("hi");
callback();
});
}
loadData(function() {
alert("hello");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment