pjs.fiber.runPromise()
This API is deprecated, starting in Profound.js 6. If you are running Profound.js 6 or higher, use async/await instead (see Promises and async/await for an example).
Description
This API calls a Promise function in a top-down manner within a fiber.
Parameters
Promise - A JavaScript promise object.
Return Value
The data passed to the promise resolve function is returned.
Exception Handling
If the promise is rejected, an error is thrown.
Examples
Run a readFile Promise in a Fiber
Run readFile Promise in a fiber
// pjs.fiber.runPromise() takes a Promise OBJECT, so readFile() is called here
// and the promise it returns is passed in.
const fs = require('fs');
const fileContent = pjs.fiber.runPromise(fs.promises.readFile('./myfile', 'utf8'));
console.log(fileContent);Read Two Files Asynchronously in Parallel in a Fiber
Read 2 files asynchronously in parallel at the same time in a fiber
// Promise.all() lets both reads run at the same time. pjs.fiber.runPromise()
// waits for all of them and returns the results in the original order.
const fs = require('fs');
const contents = pjs.fiber.runPromise(Promise.all([
fs.promises.readFile("./myfile1", 'utf8'),
fs.promises.readFile("./myfile2", 'utf8')
]));
const file1Content = contents[0];
const file2Content = contents[1];