pjs.fiber.wrapAll()
This API is deprecated, starting in Profound.js 6. If you are running Profound.js 6 or higher, use Node’s util.promisify() and async/await instead (see Promises and async/await for an example).
Description
This API wraps all asynchronous functions attached to an object so that these functions can be called in a top-down manner within a fiber. The wrapped functions are attached to a property named fiber.
This API is synonymous with pjs.fiber.wrap() used with objects.
The API assumes that the asynchronous functions accept a callback as the last parameter in the following format: function(error, response). This is typical for almost all asynchronous Node.js requests.
Parameters
Object - The object whose asynchronous functions will be wrapped.
Return Value
An object with wrapped functions.
Exception Handling
If the callback receives an error object, this error is thrown.
Examples
Run fs.readFile in a Fiber
Run fs.readFile in a fiber
// wrapAll() attaches a top-down version of every fs function under fs.fiber.
const fs = pjs.fiber.wrapAll(require('fs'));
const text = fs.fiber.readFile("somefile.txt", 'utf8');
console.log(text);Alternative Syntax
Alternative syntax
// pjs.fiber.wrap() does the same thing when it is handed an object. It also
// modifies the object in place, so the original reference can still be used.
const fs = require('fs');
pjs.fiber.wrap(fs);
const text = fs.fiber.readFile("somefile.txt", 'utf8');
console.log(text);