Using async/await in doto -> toPromise resolves to early
See original GitHub issueMy Problem is related to the version 3.0.0-beta.7
Tried to find some related issues but I didn’t find anything close to it.
I have been using an AWS Lambda and the Highland libary with some functionality on top of it. (With the new use
operator).
Everything worked like a charm until I started to use doto
with an async function. When I try to consume the stream via toPromise(...)
, it seems that the Promise resolves before every asynchronous doto
function resolved/finished. The resulting problem is, that the overall promise resolves too early, my Lambda considers his tasks as finished and aborts every ongoing request (as the process is ending) that is still pending.
However, that does not happen if I use the done
operator with an callback (So no promises involved).
The question now is, as doto
is only for side effects and async side effects are somehow hard to “track”, could this be considered a bug or just a coincidence that has to be considered?
Thanks in advance.
Code Snippets
return ...
.publishToIoTBroker(`${event.topic}/valid`) // <- My custom operator
.toPromise(Promise);
function publishToIoTBroker(...) {
...
return this.doto(async data => {
...
await iotBroker.publish(...).promise()
});
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (3 by maintainers)
I don’t anticipate that will work as intended, but I could be wrong.
Instead I would structure it like this:
This is working as intended.
doto
is only meant for synchronous side effects or asynchronous side effects for which you don’t care to wait.If you’re interested in waiting for the side effect to complete, use
flatMap
instead. There is no async version ofdoto
.