I am trying to find a way to convert a Promise to a future using the fluture library to implement functional programming, transform the data using a functional pipeline, then transform back to a promise so I can utilize await/async functionality. This is for an express app and I am using global error handling and I am not seeing how to take advantage of global error handling for endpoints if I catch errors in the future process flow without converting to a promise after the future processing is complete.
- Am I right in thinking this way?
- If so, how can I use the promise utility in the code below to translate back to a promise after the encaseP and subsequent pipeline code is called?
- Is there a better way to utilize the future pipeline while still getting errors to the global error handler?
- Also, if I do convert to a promise will that also give me access to the actual value in the future if I utilize await, I assume so?
Apologies if this is a bad question, I am a newbie to functional programming and fluture and am trying to get my ducks in the proper alignment.
const arrayList = [];
arrayList.push({
a: {
b: 1,
c: 2,
d: 3
}
},{
a: {
b: 2,
c: 3,
d: 3
}
})
const findData = (arrayList) => Promise.reject(null)
let total1 = (list) => encaseP(findData)(list)
.pipe(res => res)
.pipe(map(x => x.map(y => ({
a: {
b: y.a.b + 1,
c: y.a.c + 1,
d: y.a.d + 1
}
}))))
.pipe(promise (() => {console.log('do nothing')}) (console.log));
console.log(total1);
total1(arrayList);
When I run the code above I am getting the following error:
internal/modules/cjs/loader.js:992 internalBinding('errors').triggerUncaughtException( ^
TypeError: promise() expects its first argument to be a valid Future.