Package gets the result of analyzing references for a single package.
(ctx context.Context, id metadata.PackageID)
| 101 | |
| 102 | // Package gets the result of analyzing references for a single package. |
| 103 | func (g *PackageGraph) Package(ctx context.Context, id metadata.PackageID) (*Package, error) { |
| 104 | g.mu.Lock() |
| 105 | fut, ok := g.packages[id] |
| 106 | if ok { |
| 107 | g.mu.Unlock() |
| 108 | select { |
| 109 | case <-fut.done: |
| 110 | case <-ctx.Done(): |
| 111 | return nil, ctx.Err() |
| 112 | } |
| 113 | } else { |
| 114 | fut = &futurePackage{done: make(chan struct{})} |
| 115 | g.packages[id] = fut |
| 116 | g.mu.Unlock() |
| 117 | fut.pkg, fut.err = g.buildPackage(ctx, id) |
| 118 | close(fut.done) |
| 119 | } |
| 120 | return fut.pkg, fut.err |
| 121 | } |
| 122 | |
| 123 | // buildPackage parses a package and extracts its reference graph. It should |
| 124 | // only be called from Package. |