Skip to content

Instantly share code, notes, and snippets.

@yo1dog
Created September 16, 2016 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yo1dog/c63e94f8f9fc7a0b35a54a4bd8ed827e to your computer and use it in GitHub Desktop.
Save yo1dog/c63e94f8f9fc7a0b35a54a4bd8ed827e to your computer and use it in GitHub Desktop.
function fakeSearch(searchTerms, {onError, onComplete}) {
console.log('fakeSearch');
try {
// does some searching with searchTerms
const res = 'my dumb results';
console.log('got results');
onComplete(res);
}
catch(err) {
console.log('caught error');
onError(err);
}
}
new Promise((resolve, reject) => {
fakeSearch('fubar', {
onError: (err) => {
console.log('passwords.search onError');
reject(err);
},
onComplete: (res) => {
console.log('passwords.search onComplete');
resolve(res);
}
});
})
.catch((err) => {
console.log('promise.catch');
console.log(err);
})
.then((res) => {
console.log('promise.then');
console.log(res);
throw new Error('my dumb error'); // this is never shown
});
/*
prints:
got results
passwords.search onComplete
promise.then
my dumb results
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment