| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "reasonix/internal/control" |
| 6 | ) |
| 7 | |
| 8 | // Register only after boot success. Publication locks unwind before this join; |
| 9 | // a Close request alone can leave controller-owned persistence running. |
| 10 | func finishUnpublishedTabController(ctrl control.SessionAPI, generation uint64, published *bool) { |
| 11 | if generation == 0 || *published || ctrl == nil { |
| 12 | return |
| 13 | } |
| 14 | ctrl.Close() |
| 15 | if closed, ok := ctrl.(interface{ Closed() <-chan struct{} }); ok { |
| 16 | <-closed.Closed() |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // Unlike buildDone, done cannot be closed by a replacement generation. |
| 21 | type tabBuildExecution struct { |
| 22 | done chan struct{} |
| 23 | cancel context.CancelFunc |
| 24 | generation uint64 |
| 25 | } |
| 26 | |
| 27 | func (a *App) finishTabBuildExecution(tab *WorkspaceTab, execution *tabBuildExecution) { |
| 28 | a.mu.Lock() |
| 29 | if tab.buildExecution == execution { |
| 30 | tab.buildExecution = nil |
| 31 | } |
| 32 | delete(tab.buildExecutions, execution) |
| 33 | close(execution.done) |
| 34 | a.mu.Unlock() |
| 35 | } |
| 36 | |
| 37 | func (a *App) reportManualBuildStage(tab *WorkspaceTab, generation uint64, stage string) { |
| 38 | a.mu.RLock() |
| 39 | if tab == nil || tab.buildGeneration != generation { |
| 40 | a.mu.RUnlock() |
| 41 | return |
| 42 | } |
| 43 | id := tab.PendingCreateOperationID |
| 44 | a.mu.RUnlock() |
| 45 | a.manualCreationMu.Lock() |
| 46 | m := a.manualCreations |
| 47 | a.manualCreationMu.Unlock() |
| 48 | if m == nil || id == "" { |
| 49 | return |
| 50 | } |
| 51 | m.mu.Lock() |
| 52 | t := m.tasks[id] |
| 53 | if t != nil && !t.running { |
| 54 | t = nil |
| 55 | } |
| 56 | m.mu.Unlock() |
| 57 | if t != nil { |
| 58 | m.setStageForGeneration(t, "running", stage, generation) |
| 59 | } |
| 60 | } |
| 61 |