Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 1 | // Copyright (C) MongoDB, Inc. 2017-present. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | // not use this file except in compliance with the License. You may obtain |
| 5 | // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | |
| 7 | package options |
| 8 | |
| 9 | import "time" |
| 10 | |
| 11 | // EstimatedDocumentCountOptions represents all possible options to the estimatedDocumentCount() function |
| 12 | type EstimatedDocumentCountOptions struct { |
| 13 | MaxTime *time.Duration // The maximum amount of time to allow the operation to run |
| 14 | } |
| 15 | |
| 16 | // EstimatedDocumentCount returns a pointer to a new EstimatedDocumentCountOptions |
| 17 | func EstimatedDocumentCount() *EstimatedDocumentCountOptions { |
| 18 | return &EstimatedDocumentCountOptions{} |
| 19 | } |
| 20 | |
| 21 | // SetMaxTime specifies the maximum amount of time to allow the operation to run |
| 22 | func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions { |
| 23 | eco.MaxTime = &d |
| 24 | return eco |
| 25 | } |
| 26 | |
| 27 | // MergeEstimatedDocumentCountOptions combines the given *EstimatedDocumentCountOptions into a single |
| 28 | // *EstimatedDocumentCountOptions in a last one wins fashion. |
| 29 | func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions { |
| 30 | e := EstimatedDocumentCount() |
| 31 | for _, opt := range opts { |
| 32 | if opt == nil { |
| 33 | continue |
| 34 | } |
| 35 | |
| 36 | if opt.MaxTime != nil { |
| 37 | e.MaxTime = opt.MaxTime |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return e |
| 42 | } |