I am allowing the user to pass in a function that will be called if the user clicks on ok.
Don't. Just remove that ok
parameter from the MyConfirmation
function, and only return the promise for the button clicks. The user can then chain his function on that if he wants - or do even more.
Your call should rather look like this:
MyConfirmation('A Title', 'A message to the user').then(function(okPressed) {
if (okPressed)
return $.get('/some/bigdata/longrunning');
}).then(function(longruningResult) {
// add to dom here
});
You might also reject()
the promise when the Cancel button is pressed, then you don't need that boolean okPressed
check and could use a separate error handler instead.