Otherwise not picking up empty stream
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 145
- PR merge metrics
- No merged PRs in 30d
Description
In my application repo I have the following function. I stream an immutable object down the pipeline. It filters it to see if we need to run a git diff to determine if we should copy the last version's assets or run a full build. However, it appears that after filter runs and if it returns false, that otherwise never fires. The stream appears to end, however it works completely as expected in my unit test. Does any cause come to mind which as to why the stream stops if that filter function returns false? I've put a console log statement in the `otherwise` stream-returning function but it does not fire.
```js
function getBuildAction (stream) {
let stateStream = stream.observe();
return stream
// Only process when we know there is a newer version of the source
.filter((state) => state.lastAssetVersion !== state.currentAssetVersion)
// Diff the repo against the target branch & emit diff files
.flatMap((state) => runGitDiff(state.sourceDir))
// Flip back to original state stream if diff was not required
.otherwise(stateStream)
}
```
The code before it also runs from an observe like this:
```js
function createBuildStream (stateStream) {
let buildStream = stateStream.observe();
buildStream
.through(getBuildAction) // Where the stream stops
.through(buildProcess) // Runs a bunch of commands
.pipe(writeToLog()); // returns fs.createWriteStream
return stateStream;
}
```
Contributor guide
Research direction
Start with getBuildAction and createBuildStream, then inspect how observe, filter, flatMap, and otherwise handle completion and empty streams. Compare this pipeline with the unit-test case that succeeds and trace whether the filtered stream completes or routes values as expected. Done means the cause is reproducible and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- stream-processing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100