Ensuring completion-listener.ts listen to a single close event emitte…#464
Ensuring completion-listener.ts listen to a single close event emitte…#464gustavohenke merged 11 commits intoopen-cli-tools:mainfrom
Conversation
…d from each command.
|
Rethinking on this, this change includes also an edge case that doesn't work:
---> It will resolve altho the first command is also alive So I might be going on the wrong direction here would love to here your tought on the initial design of the |
|
Another option would be a design-level change such as: Adding a new And a modification for Would love to hear your mind on it 👍 |
gustavohenke
left a comment
There was a problem hiding this comment.
Restarting is tricky; because each option you set changes the closing conditions of a command, the flow controllers wrap the close observable so that all looks simple on the completion listener side.
Adding a new restart API
I think this could be done for convenience, but not as a way of fixing this issue.
this change includes also an edge case that doesn't work:
This is true, but this PR is at least an improvement over not doing anything.
The optimal solution is probably to retain the last emitted close event of each command until they all exit.
|
So how would u recommend proceeding? Do you wish to have this fix for now? (as you said just a slight improvement for the current state) |
src/completion-listener.ts
Outdated
|
|
||
| return Rx.lastValueFrom( | ||
| Rx.merge(...closeStreams).pipe( | ||
| bufferCount(closeStreams.length), |
There was a problem hiding this comment.
So how would u recommend proceeding?
I think that replacing these lines with Rx.combineLatest() + removing the take(1) above can achieve retaining the last emitted close event.
We can then also fix your edge case from #464 (comment) with a filter() operator that checks if every command is indeed closed.
This means waiting until every command emits another close event.
WDYT?
There was a problem hiding this comment.
Yea that sounds legit, at-least the first part, seems like combineLatest can do the job 👍 Ill try to change the implementation accordingly
There was a problem hiding this comment.
@gustavohenke I've pushed the changes, the only drawback using the combineLatest is that it actually keep the close events according to the registered stream and not by the actual order they were emitted, So beside accepting your offer I also added a map to sort it via the startingDate of the event, would love to hear if you got any better suggestion here 👍
-Adding `ipc` option by default. -Adjusting specs.
src/completion-listener.ts
Outdated
| Rx.merge(...closeStreams).pipe( | ||
| bufferCount(closeStreams.length), | ||
| Rx.combineLatest(closeStreams).pipe( | ||
| filter((exitInfos) => exitInfos.every((exitInfo) => exitInfo.exitCode !== null)), |
There was a problem hiding this comment.
exitCode is never null here. You need to look at the event's command for the current state
| filter((exitInfos) => exitInfos.every((exitInfo) => exitInfo.exitCode !== null)), | |
| filter((exitInfos) => exitInfos.every(({ command }) => command.state !== 'started')), |
There was a problem hiding this comment.
Yea good point 👍 This means to access it we would need to either add it to the CommandInfo which I assume we don't want as it's a public interface or send it explicitly right?
There was a problem hiding this comment.
Heya, I've fixed this myself and added an extra test too.
You were right, adding to CommandInfo is not a good idea, but so wasn't right to pass the state in the close event since that's pretty static. Can check commands variable just outside the loop, though.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
Hey! This is now available in v9.0.0. |
Currently, the
CompletionListenersets abufferCountupon commands close streams to conclude once commands are finished and then evaluates the exit code and determines thesuccess/failconditions.Continued to the issue brought here, calling manually
Command-kill/startAPI's manually, causes a bug where theCompletionListenerresolves before all commands had exited ( as a single command can emit multiple close events ).This PR changes the behaviour to take a single emit event from each command in order to conclude termination.
Disclaimer:
Potentially I would love to find a way to take the last exit command emitted from each
Commandtho I couldn't find a way would appreciate any suggestion 👍 mine while I kept things the same.Side effects
completion-listener.spec.tsfile to all use the same command exit helperAllowipcfor spawned commandsResolves: #463