@@ -29,50 +29,35 @@ mind maps, highlights and more.`,
2929func Execute (version , commit , date string ) {
3030 rootCmd .Version = fmt .Sprintf ("%s (commit %s, built %s)" , version , commit , date )
3131
32- updateCh := maybeStartUpdateCheck (version )
32+ var updateResult * update.Result
33+ maybeStartUpdateCheck (version , & updateResult )
3334
3435 if err := rootCmd .Execute (); err != nil {
3536 async .Wait () // Wait for background tasks before exit
3637 os .Exit (1 )
3738 }
3839
39- printUpdateNotice ( updateCh )
40- async . Wait () // Wait for background tasks before exit
40+ async . Wait () // Wait for background tasks (including update check) before exit
41+ printUpdateNotice ( updateResult )
4142}
4243
43- // maybeStartUpdateCheck starts an async update check and returns a channel that
44- // will receive the result. The channel is closed immediately when the check
45- // should be skipped (MCP mode, non-TTY, or PODWISE_NO_UPDATE_CHECK env var set).
46- func maybeStartUpdateCheck (version string ) <- chan update.Result {
47- ch := make (chan update.Result , 1 )
48-
44+ // maybeStartUpdateCheck starts an async update check using the async package.
45+ // The check is skipped in MCP mode, non-TTY environments, or when PODWISE_NO_UPDATE_CHECK is set.
46+ // The result is stored in the provided pointer after the check completes.
47+ func maybeStartUpdateCheck (version string , result * * update.Result ) {
4948 if isMCPCommand () || ! isTerminal (os .Stderr ) || os .Getenv ("PODWISE_NO_UPDATE_CHECK" ) != "" {
50- close (ch )
51- return ch
49+ return
5250 }
5351
54- go func () {
55- ch <- update .Check (version )
56- }()
57-
58- return ch
52+ async .Go (func () {
53+ r := update .Check (version )
54+ * result = & r
55+ })
5956}
6057
61- // printUpdateNotice performs a non-blocking read of the update channel and
62- // prints a notice to stderr when a newer version is available.
63- func printUpdateNotice (ch <- chan update.Result ) {
64- var result update.Result
65- select {
66- case r , ok := <- ch :
67- if ! ok {
68- return
69- }
70- result = r
71- default :
72- return
73- }
74-
75- if ! result .HasUpdate {
58+ // printUpdateNotice prints a notice to stderr when a newer version is available.
59+ func printUpdateNotice (result * update.Result ) {
60+ if result == nil || ! result .HasUpdate {
7661 return
7762 }
7863
0 commit comments