Created
December 28, 2017 12:12
-
-
Save dac09/e5de547d8d3dcafabbb349d3d2bb6966 to your computer and use it in GitHub Desktop.
Resolving promise externally
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
async function showRationaleDialog(title: string, message: string) { | |
let done; | |
const result = new Promise(resolve => { | |
done = resolve; | |
}); | |
const alert = Alert.alert(title, message, [ | |
{ | |
text: 'OK', | |
onPress: () => done() | |
} | |
]); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Essentially hoists the resolve function outside the promise creation block, then calls it when ready.