Fix deep context usage
A few methods were creating a new context, this is a bad pattern.
These issues were in oviewer/move_vertical.go for the following methods:
- nextSection
- prevSection
Because of these 2 functions code had to be refactored to pass func(context.Context) everywhere needed.
Fixes #539 539
Here are two things I would like to discuss with you @noborus
- asymetric code
why prevSection has a timeout https://github.com/noborus/ov/blob/64bd638fdf21036aecde885683f958bd93a7204a/oviewer/move_vertical.go#L298-L306
while nextSection doesn't
https://github.com/noborus/ov/blob/64bd638fdf21036aecde885683f958bd93a7204a/oviewer/move_vertical.go#L309-L323
- should we add a context on Run
https://github.com/noborus/ov/blob/7106978e6cbda664896eda0c6534f676f5f8493a/oviewer/oviewer.go#L592-L595
It's usually a bad idea to do not set up the context in main.go
This branch has to be tested by building the binary and launching it locally.
You know the tool and all the use cases.
thank you.
Something strange happened because I kept adding context later. I think this pull request is correct.
Here are two things I would like to discuss with you @noborus
- asymetric code
why prevSection has a timeout
https://github.com/noborus/ov/blob/64bd638fdf21036aecde885683f958bd93a7204a/oviewer/move_vertical.go#L298-L306
while nextSection doesn't
The reason prevSection has a timeout is because section-header is using it. If you move to the end of a large file and then specify a non-existent line as section-header, the program will freeze while searching for section-header. This is to prevent that. Originally, a timeout should be inserted on the section-header side, but the fix was postponed.
Here are two things I would like to discuss with you @noborus
- asymetric code
why prevSection has a timeout
https://github.com/noborus/ov/blob/64bd638fdf21036aecde885683f958bd93a7204a/oviewer/move_vertical.go#L298-L306
while nextSection doesn't
The reason prevSection has a timeout is because section-header is using it. If you move to the end of a large file and then specify a non-existent line as section-header, the program will freeze while searching for section-header. This is to prevent that. Originally, a timeout should be inserted on the section-header side, but the fix was postponed.
Great explanation, you should comment the code accordingly then.
And maybe create an issue for the postponed fix
Great explanation, you should comment the code accordingly then.
And maybe create an issue for the postponed fix
I agree. For now, I'll add a comment.
You are not funny, your changes led to conflicts 😅
Next time, please append it to my PR, there were no rush to add the comment 😂
sorry. solved.
sorry. solved.
Thanks
Feel free to test and merge
I agree with you, you will have to define the timeout in the caller function. It should be way easier now I refactored everything to pass context.
So feel free to add it in this PR or another.
I'm going to merge! Thank you very much.