Using async/await in doto -> toPromise resolves to early
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
**My 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
```js
return ...
.publishToIoTBroker(`${event.topic}/valid`) // <- My custom operator
.toPromise(Promise);
```
```js
function publishToIoTBroker(...) {
...
return this.doto(async data => {
...
await iotBroker.publish(...).promise()
});
}
```
Contributor guide
Research direction
Start by reproducing the interaction between doto with an async function and toPromise(Promise), using the publishToIoTBroker example in the issue. Compare its completion behavior with the done operator and callback, then determine whether toPromise should wait for the asynchronous side effect before resolving.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- stream-processing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100