pjs.fiber.wrapNoFail()

This API is deprecated, starting in Profound.js 6. If running Profound.js 6 or higher, use Node's util.promisify() and async/await instead. See here for an example.

This API wraps an asynchronous function so that it can be called in a top-down manner within a fiber. If the asynchronous call fails, no error is thrown; instead, it is attached to the return value.

The API assumes that the function accepts a callback as its last parameter in the following format:

function(error, response)

This is typical for virtually all asynchronous Node.js requests.

The API can also accept an object which contains a set of asynchronous functions, in which case it will act the same as the pjs.fiber.wrapAllNoFail() API.

Parameters


  • asynchronous function
  • this argument (optional)

Alternative Parameters


  • object containing asynchronous functions

Return Value


Top-down function that returns an object with the following properties:

  • success
    value: true or false
  • error
    value: error object (if success is false)
  • output
    value: response output (if success is true)

Exception Handling


No exceptions are thrown by this API.

Examples

Run fs.readFile in a fiber
const fs = require('fs');
var readFile = pjs.fiber.wrapNoFail(fs.readFile);
var response = readFile("somefile.txt", 'utf8');
var text = "";
if (response.success) text = response.output;
else console.log(response.error);

Video Tutorial