Consider following case:
var Calc = function () {
// proprties
this.value = 0
// handler's
this.Add = (__value) => { this.value = this.value + __value; return this }
this.Subtract = (__value) => { this.value = this.value - __value; return this }
}
var = (new Calc()).Add(2).Subtract(1) // console.log() => 1
but if you wrap Object in async await something like
var Calc = async function () {
// proprties
this.value = 0
// handler's
this.Add = async (__value) => { this.value = this.value + __value; return this }
this.Subtract = async (__value) => { this.value = this.value - __value; return this }
}
(await new Calc()).Add(2).Subtract(1) // console.log() => undefined
(await (await new Calc()).Add(2)).Subtract(1) // console.log() => 1
I know the reason as Promise is returned it need to be resolved for that you just wrap your code inside () and once statement is executed you can continue chain.
What i am looking for.
await newCalc().Add(2).Subtract(1) // console.log() => 1
Calcnot a class?asyncin front of anything does not make sense. Even if those opsAddandSubtractasyncwhy does theCalcfunction isasync. And doubleawaitwhy? what is it that u need to accomplish here.