You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During some async operation, I render a status message to the console. My console command has a --raw option that, if specified, prevents "superfluous" output to the console. In this case, that means that the Status() text should not be rendered.
It's not apparent to me that there is an idiomatic mechanism to do this. The reason that's important here is because it affects how I organize the code. Right now, I feel my only option is to do something like this:
This is really ugly, but that's not the main issue. The duplication of code within the lambda is of concern.
Is there already an idiomatic (intrinsic) method of disabling console output in this scenario?
If not, I think it would be nice if Status() took an optional parameter to disable the output. Basically, it would cause the lambda expression to be executed directly instead of any intermediate rendering logic. So my example above transforms into something like this:
I managed to simplify a little further, but it's still nasty and it would be great to have a way to elide the console rendering at runtime somehow. I'm happy to provide a PR for this, but I'd like some design guidance as I imagine a simple boolean flag like I've demonstrated isn't going to be desirable.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a method like this:
During some async operation, I render a status message to the console. My console command has a
--raw
option that, if specified, prevents "superfluous" output to the console. In this case, that means that theStatus()
text should not be rendered.It's not apparent to me that there is an idiomatic mechanism to do this. The reason that's important here is because it affects how I organize the code. Right now, I feel my only option is to do something like this:
This is really ugly, but that's not the main issue. The duplication of code within the lambda is of concern.
Is there already an idiomatic (intrinsic) method of disabling console output in this scenario?
If not, I think it would be nice if
Status()
took an optional parameter to disable the output. Basically, it would cause the lambda expression to be executed directly instead of any intermediate rendering logic. So my example above transforms into something like this:EDIT:
I managed to simplify a little further, but it's still nasty and it would be great to have a way to elide the console rendering at runtime somehow. I'm happy to provide a PR for this, but I'd like some design guidance as I imagine a simple boolean flag like I've demonstrated isn't going to be desirable.
Beta Was this translation helpful? Give feedback.
All reactions