Skip to content
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

Refreshintervals less than one second #1139

Merged

Conversation

ResamVi
Copy link
Contributor

@ResamVi ResamVi commented Oct 29, 2021

Solves #1103
In continuation of #1120

This feature made wtf hang up and couldn't be exit with ctrl+c:

So what happened is that the textfile module is not using the Schedule function like every other module does.
Instead it deploys it's own scheduling logic in watchForFileChanges because - unlike every other module - it refreshes on file changes instead of regular intervals.

That logic however didn't listen to ctrl+c and wouldn't properly exit.
So I simply added the below case for it to work. Now WTF properly exits.

func (widget *Widget) watchForFileChanges() {
	watch := watcher.New()
	watch.FilterOps(watcher.Write)

	go func() {
		for {
			select {
			case <-watch.Event:
				widget.Refresh()
			case err := <-watch.Error:
				fmt.Println(err)
				os.Exit(1)
			case <-watch.Closed:
				return
+			case quit := <-widget.QuitChan():
+				if quit {
+					return
+				}
			}
		}
	}()

Changing from int to time.Duration somehow unearthed this problem and I don't really know why.

I've changed all instances of refreshInterval int to refreshInterval time.Duration in every module to keep it completely consistent and not have any loose ends open.

@senorprogrammer
Copy link
Collaborator

Awesome work 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants