Last active
April 15, 2019 06:14
-
-
Save hoodwink73/b5b8059028a899d811802fb4f45ba7ef to your computer and use it in GitHub Desktop.
Error handling with Asynquence is a bit different. By default a error in the sequence suspends the entire sequence.
This file contains hidden or 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
ASQ() | |
.promise(delayWithReject(200)) | |
.or(() => console.log('caught')) | |
.val(() => console.log('The sequence deactivates. So this never gets logged.')) | |
ASQ() | |
// a `try` always ends up in a sequence progress | |
// in case the task fails the next step will receive a special messsage | |
// -> {error: "Reason for failure" } | |
.try((done) => done.fail('Doomed!!')) | |
.or(() => console.log('caught')) | |
.val((message) => console.log('The sequence would proceed either way', message)) |
This file contains hidden or 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
var ASQ = require('asynquence-contrib') | |
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | |
const delayWithReject = (ms) => new Promise((resolve, reject) => setTimeout(reject, ms)) | |
delayWithReject(200) | |
.catch(() => console.error('caught')) | |
.then(() => delay(200)) | |
.then(() => console.log('The chain is restored')) | |
// unhandled error does not restore the chain | |
delayWithReject(400) | |
.then(() => delay(200)) | |
.then(() => console.log('The chain never gets restored')) |
This file contains hidden or 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
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) | |
const delayWithReject = (ms) => new Promise((resolve, reject) => setTimeout(reject, ms)) | |
ASQ() | |
.promise(delay(200)) | |
.val(() => {console.log('boom')}) | |
.or(() => {console.error('bam')}) // this gets logged | |
.promise(delayWithReject(400)) | |
// my expected behavior is to see just this get logged | |
.or(() => console.error('caught')) // this also gets logged |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment