Created
September 16, 2016 00:34
-
-
Save yo1dog/c63e94f8f9fc7a0b35a54a4bd8ed827e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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