You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 7, 2020. It is now read-only.
Update: Changed subject to reflect the current focus.
I tried out the example at https://github.com/getify/asynquence/blob/master/contrib/README.md#errfcb-plugin that talks about sq.errfcb() plugin. When I execute the code, the parameter passed to .then() doesn't seem to have the desired data. (That's the data which would have been passed as the second parameter of the error-first callback). How is it made available?
// first install with "npm install asynquence"
var ASQ = require("asynquence-contrib");
fs = require("fs");
// Node.js: fs.readFile(..) wrapper
function readFile(filename) {
// setup an empty sequence (much like an empty
// promise)
var sq = ASQ();
// call Node.js' `fs.readFile(..), but pass in
// an error-first callback that is automatically
// wired into a sequence
fs.readFile( filename, 'utf8', sq.errfcb() );
// now, return our sequence/promise
return sq;
}
readFile("/Users/richb/meaningoflife.txt")
.then((data) =>
{ console.log("Read fine...", data) })
.or((err) =>
{ console.log("Error", err) })
Update: added 'utf8' parameter to fs.readFile() so that resulting data is a string, not a buffer.