DEV Community

FaithInErrors
FaithInErrors

Posted on

New to node how can I make these basic area functions async using node

`let areaCircle = (radius) => {
return Math.PI * radius * radius
}

let areaRect = (length, width) =>{
return (length * width)
}

exports.areaCircle = areaCircle
exports.areaRect = areaRect

`

Top comments (1)

Collapse
 
faith_in_errors_7fe9c90f68151 profile image
FaithInErrors

actually i am pretty sure I have resolved it like so
`let areaCircle = (radius, done) => {
process.nextTick(() => {
let result = Math.PI * radius * radius;
done(null, result)
});
}

let areaRect = (length, width, done) =>{
process.nextTick(()=>{
let result = length * width
done(null, result)
});
}

module.exports = geometry;
`

and then calling them I would have to add the error handling ?

`const geometry = require("./modules/bModule.js");

geometry.areaCircle(3, (err, results) => {
if (err) {
throw err;
}
console.log(results.toFixed(2));
});

geometry.areaRect(4, 6, (err, results) => {
if (err) {
throw err;
}
console.log(results);
});`