Skip to content
This repository was archived by the owner on Dec 7, 2020. It is now read-only.
This repository was archived by the owner on Dec 7, 2020. It is now read-only.

Comments on Documentation #82

@richb-hanover

Description

@richb-hanover

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions