| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "log/slog" |
| 5 | "os" |
| 6 | |
| 7 | "reasonix/internal/boot" |
| 8 | "reasonix/internal/skill/skillwatch" |
| 9 | ) |
| 10 | |
| 11 | // sharedSkillWatchService returns the one skill-watch service this host shares |
| 12 | // across every controller it builds. |
| 13 | // |
| 14 | // Each service owns a helper process: a service per build spawned a 56MB |
| 15 | // reasonix-desktop.exe and tore one down on every tab-controller rebuild, and |
| 16 | // because a helper lives until its build is closed, rebuilds left several |
| 17 | // resident at once. One service per host keeps exactly one helper for the |
| 18 | // process lifetime. |
| 19 | func (a *App) sharedSkillWatchService() *skillwatch.Service { |
| 20 | if a == nil { |
| 21 | return nil |
| 22 | } |
| 23 | a.skillWatchMu.Lock() |
| 24 | defer a.skillWatchMu.Unlock() |
| 25 | if a.skillWatch == nil { |
| 26 | a.skillWatch = boot.NewHostSkillWatchService(os.Stderr) |
| 27 | } |
| 28 | return a.skillWatch |
| 29 | } |
| 30 | |
| 31 | // closeSharedSkillWatchService closes the host watcher; boot.Build leaves a |
| 32 | // caller-owned service alone, so nothing else closes it. The closed service |
| 33 | // stays in place: a build racing shutdown gets dead subscriptions from it |
| 34 | // instead of a fresh helper process that nothing would close. |
| 35 | func (a *App) closeSharedSkillWatchService() { |
| 36 | if a == nil { |
| 37 | return |
| 38 | } |
| 39 | a.skillWatchMu.Lock() |
| 40 | service := a.skillWatch |
| 41 | a.skillWatchMu.Unlock() |
| 42 | if service == nil { |
| 43 | return |
| 44 | } |
| 45 | if err := service.Close(); err != nil { |
| 46 | slog.Warn("desktop: close skill watch service", "err", err) |
| 47 | } |
| 48 | } |
| 49 |