MCPcopy Create free account
hub / github.com/github/gh-aw / StartCompileUpdateCheck

Function StartCompileUpdateCheck

pkg/cli/compile_update_check.go:59–104  ·  view source on GitHub ↗

StartCompileUpdateCheck begins a best-effort update check for the compile command. The returned function should be called once before the command exits to print any ready notification without blocking compilation for long.

(ctx context.Context, noCheckUpdate bool, verbose bool)

Source from the content-addressed store, hash-verified

57// The returned function should be called once before the command exits to print any
58// ready notification without blocking compilation for long.
59func StartCompileUpdateCheck(ctx context.Context, noCheckUpdate bool, verbose bool) func() {
60 if !shouldRunCompileUpdateCheck(noCheckUpdate) {
61 return func() {}
62 }
63 updateCompileUpdateCheckTime()
64
65 results := make(chan *compileUpdateNotification, 1) // buffered channel closed by sender goroutine via defer
66
67 go func() {
68 defer close(results)
69 defer func() {
70 if r := recover(); r != nil {
71 compileUpdateCheckLog.Printf("Panic in compile update check (recovered): %v", r)
72 }
73 }()
74
75 if ctx.Err() != nil {
76 compileUpdateCheckLog.Printf("Compile update check cancelled before starting: %v", ctx.Err())
77 return
78 }
79
80 result, err := runCompileUpdateCheck(ctx, compileUpdateCheckHTTPClientFactory())
81 if err != nil {
82 compileUpdateCheckLog.Printf("Compile update check failed (ignoring): %v", err)
83 return
84 }
85 if result == nil {
86 if verbose {
87 compileUpdateCheckLog.Print("No compile update notification needed")
88 }
89 return
90 }
91
92 select {
93 case results <- result:
94 case <-ctx.Done():
95 }
96 }()
97
98 return func() {
99 result := waitForCompileUpdateNotification(ctx, results, compileUpdateCheckNoWait)
100 if result != nil {
101 printCompileUpdateNotification(result)
102 }
103 }
104}
105
106func shouldRunCompileUpdateCheck(noCheckUpdate bool) bool {
107 if noCheckUpdate {

Calls 8

runCompileUpdateCheckFunction · 0.85
PrintMethod · 0.80
DoneMethod · 0.80
PrintfMethod · 0.45