| 1 | package sessioncatalog |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | |
| 6 | "reasonix/internal/projectiondb" |
| 7 | ) |
| 8 | |
| 9 | func (c *Catalog) Close(ctx context.Context) error { |
| 10 | if c == nil { |
| 11 | return nil |
| 12 | } |
| 13 | c.stopOnce.Do(func() { |
| 14 | if c.workerCancel != nil { |
| 15 | c.workerCancel() |
| 16 | } |
| 17 | close(c.stop) |
| 18 | go func() { |
| 19 | c.closeReadLeases() |
| 20 | c.workers.Wait() |
| 21 | projectiondb.CheckpointBeforeClose(context.Background(), c.db) |
| 22 | c.closeErr = c.db.Close() |
| 23 | c.statusMu.Lock() |
| 24 | c.status.State = StateClosed |
| 25 | c.statusMu.Unlock() |
| 26 | close(c.closeDone) |
| 27 | }() |
| 28 | }) |
| 29 | select { |
| 30 | case <-c.closeDone: |
| 31 | return c.closeErr |
| 32 | case <-ctx.Done(): |
| 33 | return ctx.Err() |
| 34 | } |
| 35 | } |
| 36 |