Created
April 18, 2018 15:22
-
-
Save Flayed/2efb8682c01e5471ccb2fbe318c7b9f4 to your computer and use it in GitHub Desktop.
TypeScript promise
This file contains hidden or 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
// A long running thing | |
doTheThing(a: number, b: number): Promise<boolean> { | |
return new Promise<boolean>((resolve, reject) => { | |
// Long running call (just pretend, ok?) | |
const c = a + b; | |
if (c > 0) { | |
resolve(true); | |
} | |
else { | |
resolve(false); | |
} | |
}); | |
} | |
// Calling the long running thing | |
doSomethingWithTheThing() { | |
this.doTheThing(1, 1).then((result) => { | |
if (result) { | |
alert('The thing worked!'); | |
} else { | |
alert('The thing did not worked :('); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment