-
Notifications
You must be signed in to change notification settings - Fork 8.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaner Pid observable code #12702
Cleaner Pid observable code #12702
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
platform/plugins/pid/PidService.ts
Outdated
} | ||
|
||
// Otherwise we return an observable that writes the pid when | ||
// subscribed to and deletes it when unsubscribed (e.g. if new config | ||
// is received or if `stop` is called below.) | ||
|
||
return new Observable<PidFile | void>(observable => { | ||
return new Observable(observable => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: observable
argument is not used, so we can get rid of it.
.switchMap(config => { | ||
if (config === undefined) { | ||
// If there is no pid config we return an observable that does nothing | ||
return new Observable(noop); | ||
} | ||
|
||
// Otherwise we return an observable that writes the pid when | ||
// subscribed to and deletes it when unsubscribed (e.g. if new config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: does e.g. if new config is received
mean I can change pid file path on-the-fly and old file will be deleted and new one created? Is it supposed to work at the moment (didn't manage to see that behaviour)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then sighup the process (kill -1 it)
Ah, that the reason, I didn't do that (for some reason I thought we watch the config file for changes all the time), thanks :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watching is "less safe" as you can be in intermediate states when it triggers. E.g. if you're moving stuff around in the config and hit save at some point (e.g. my IDE that saves whenever I cmd-tab away). It's better to let the user actively notify that the config is ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree
The code became simpler when moving the config stuff into the
switchMap
. Otherwise just some minor cleanups.