CostObserver provides an observer that tracks runtime cost.
(opts ...CostTrackPlanOption)
| 97 | |
| 98 | // CostObserver provides an observer that tracks runtime cost. |
| 99 | func CostObserver(opts ...CostTrackPlanOption) PlannerOption { |
| 100 | ct := &costTrackerFactory{} |
| 101 | for _, o := range opts { |
| 102 | ct = o(ct) |
| 103 | } |
| 104 | return func(p *planner) (*planner, error) { |
| 105 | if ct.factory == nil { |
| 106 | return nil, errors.New("cost tracker factory not configured") |
| 107 | } |
| 108 | p.costTrackerFactory = ct.factory |
| 109 | return p, nil |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | // costTrackerFactory holds a factory for producing new CostTracker instances on each Eval call. |
| 114 | type costTrackerFactory struct { |