From 159cd136ff12cf1c269c57e942479b2cf46d1fcc Mon Sep 17 00:00:00 2001 From: Shulhan Date: Thu, 9 Nov 2023 00:15:21 +0700 Subject: all: add method to stop watcher With the latest update on lib/memfs, we can stop the watcher internally. --- server.go | 4 ++++ watcher.go | 7 +++++++ watcher_test.go | 2 ++ 3 files changed, 13 insertions(+) diff --git a/server.go b/server.go index 384b164..778ca5d 100644 --- a/server.go +++ b/server.go @@ -129,6 +129,10 @@ func (srv *server) start() (err error) { return fmt.Errorf(`%s: %w`, logp, err) } + if srv.opts.IsDevelopment { + srv.watcher.stop() + } + return nil } diff --git a/watcher.go b/watcher.go index 2dbbfef..81108bc 100644 --- a/watcher.go +++ b/watcher.go @@ -100,6 +100,13 @@ func (w *watcher) start() (err error) { return nil } +func (w *watcher) stop() { + w.watchDir.Stop() + if w.watchTemplate != nil { + w.watchTemplate.Stop() + } +} + // watchFileMarkup watch the markup files inside the "content" directory, // and re-generate them into HTML file when changed. func (w *watcher) watchFileMarkup() { diff --git a/watcher_test.go b/watcher_test.go index 331e2c5..6136afc 100644 --- a/watcher_test.go +++ b/watcher_test.go @@ -90,6 +90,8 @@ func TestWatcher(t *testing.T) { t.Run(`testMarkdownDelete`, func(tt *testing.T) { testMarkdownDelete(tt, testWatcher, pathFileMarkup) }) + + testWatcher.stop() } func testAdocCreate(t *testing.T, testWatcher *watcher, tdata *test.Data, pathFile string) { -- cgit v1.3