mirror of
https://github.com/mum4k/termdash.git
synced 2026-04-27 03:15:55 +03:00
[GH-ISSUE #241] Pass context.Context to Controlller #131
Labels
No labels
bug
cleanup
enhancement
enhancement
enhancement
good first issue
help wanted
help wanted
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/termdash#131
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @flaviostutz on GitHub (Jul 29, 2020).
Original GitHub issue: https://github.com/mum4k/termdash/issues/241
Originally assigned to: @mum4k on GitHub.
I have a case where I need to control the "redraw" timing more accuratelly, so I am using Controller interface and "redraw()", but when closing the program, I am having some trouble and I think it is due to double closing the terminal due to the lack of context control.
I think it would be great for us to pass the context.Context to the controller so that one can control better the execution flow.
Using this code:
I have this log when exiting the application:

I wish I could use
@mum4k commented on GitHub (Jul 29, 2020):
Hi @flaviostutz, the code snippets that you filed with the bug are only partial, so I had to guess the rest. I think I managed to recreate the problem. There seem to be two issues here and unless I am mistaken, they are both in the code you pasted. I.e. I didn't find a bug in the termdash code, but please feel free to correct me if I missed anything. Here's what I found:
This seems to be the result of calling Close() on the terminal twice. I don't see how you initialise the terminal in your code, but I am going to guess that it is using this code:
If yes, the call to
t.Close()is deferred above, but there is also a second call tot.Close()in the code snippet you linked, just under the call tocontroller.Close(). If that is the case, please try removing one of the two.This is unrelated and an observation that you might find useful. The ticker for loop doesn't actually terminate when the context closes. It continues to run and it has a chance to call another
controller.Redraw()after the context closed and the controller closed. I would suggest breaking from the loop, the relevant portion:Alternatively you can avoid the ugly break label by placing the entire loop into a separate function and just returning instead of breaking.
Please let me know if this helped. If this didn't address the issue, please attach the complete code that will help me to reproduce and troubleshoot.
@flaviostutz commented on GitHub (Jul 30, 2020):
Thanks, @mum4k, and sorry for the incomplete code I put at first. You did an excellent job analyzing this!
Let me put the whole code here for a better analysis. I made it work by "resolving" the error during close, but I think there is something wrong or with my code or with termdash.
Here it is:
See the whole project at https://github.com/flaviostutz/perfstat/blob/master/cli/main.go and thanks for your great work here!
@mum4k commented on GitHub (Jul 30, 2020):
Thank you for pasting the full code. Can you help me understand what you mean by " there is something wrong or with my code or with termdash"?
Is there an error message you can share or an error description?
@mum4k commented on GitHub (Nov 14, 2020):
Going to close this for inactivity, but please feel free to reopen if you would like to continue the discussion.