Async/await and try/catch
This example demonstrates how to use async/await and try/catch in order to retrieve what the users response within the prompt was.
The essential piece to take from this is that the showPrompt
callback returns a promise that represents the outcome of the prompt. You can either resolve
or reject
it and return the result to the caller as you might expect when using try/catch
.
Note that you don’t have to use try/catch
, you can just always resolve
from within your prompt and then only worry about the result returned from the promise.