Created
July 25, 2016 18:25
-
-
Save rehia/6b13bd8202a37fbb58c82cbdd9df9b83 to your computer and use it in GitHub Desktop.
Strange behavior with co, `yield*`, promises, and Node (v. 6.3.1)
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
/somewhere/yield.js:14 | |
throw reason; | |
^ | |
Error: test value a has some problems | |
at Promise (/somewhere/yield.js:19:12) | |
at display (/somewhere/yield.js:18:10) | |
at Array.map (native) | |
at /somewhere/yield.js:10:28 | |
at next (native) | |
at onFulfilled (/somewhere/node_modules/co/index.js:65:19) | |
at /somewhere/node_modules/co/index.js:54:5 | |
at co (/somewhere/node_modules/co/index.js:50:10) | |
at Object.<anonymous> (/somewhere/yield.js:6:1) | |
at Module._compile (module.js:541:32) |
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
/somewhere/yield.js:14 | |
throw reason; | |
^ | |
TypeError: Cannot read property 'done' of undefined | |
at next (/somewhere/node_modules/co/index.js:98:14) | |
at onRejected (/somewhere/node_modules/co/index.js:85:7) | |
at runMicrotasksCallback (internal/process/next_tick.js:58:5) | |
at _combinedTickCallback (internal/process/next_tick.js:67:7) | |
at process._tickCallback (internal/process/next_tick.js:98:9) | |
at Module.runMain (module.js:577:11) | |
at run (bootstrap_node.js:352:7) | |
at startup (bootstrap_node.js:144:9) | |
at bootstrap_node.js:467:3 |
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
'use strict'; | |
const co = require('co'); | |
const values = ['a']; | |
co(function* () { | |
console.log('start'); | |
setTimeout(() => console.log('end'), 1000); // just here to confirm that the node task is stopped before timeout | |
// yield* values.map(display); | |
yield Promise.all(values.map(display)); | |
}); | |
process.on('unhandledRejection', (reason, p) => { | |
throw reason; | |
}); | |
function display(value) { | |
return new Promise((fulfill, reject) => { | |
reject(new Error(`test value ${value} has some problems`)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment