Skip to content

Instantly share code, notes, and snippets.

@dac09
Created December 28, 2017 12:12
Show Gist options
  • Save dac09/e5de547d8d3dcafabbb349d3d2bb6966 to your computer and use it in GitHub Desktop.
Save dac09/e5de547d8d3dcafabbb349d3d2bb6966 to your computer and use it in GitHub Desktop.
Resolving promise externally
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;
}
@dac09
Copy link
Author

dac09 commented Dec 28, 2017

Essentially hoists the resolve function outside the promise creation block, then calls it when ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment