class Calculation {
constructor(num) {
this.num = num;
}
performAddition() {
// code
}
performSubtraction() {
// code
}
performMultiplication() {
// code
}
performDivision() {
// code
}
}
const getResult = async () => {
const result = await new Calculation(10)
.performAddition(30)
.performSubtraction(5)
.performMultiplication(2);
console.log(result); //prints the final result
};
getResult();
Is there a way to achieve chaining of methods in JavaScript where each method can be awaited for asynchronous execution, similar to mongoose queries?
Although regular calculations are synchronous, if we were to consider them as asynchronous operations, what would be the correct implementation to achieve the desired functionality?