I got a custom confirm dialog which waits for user input. I'm wrapping it in a promise.
When the user is choosing the "yes" alternative I resolve
the promise.
However, when the user chooses no
it's not really an error but more that the next task should not be executed.
How should I handle that scenario with the promise? simply not invoke resolve/reject or is there a better approach?
You could resolve a value and check that value afterwards.
new Promise((resolve, reject) => {
const userInput = confirm('Do you want to continue?');
resolve(userInput);
}).then(input => {
if(input) {
// Do something
} else {
// Do something else
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With