Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Make an OperationDeadlinePolicy interface #49

Open
software-dov opened this issue May 6, 2019 · 0 comments
Open

Make an OperationDeadlinePolicy interface #49

software-dov opened this issue May 6, 2019 · 0 comments

Comments

@software-dov
Copy link
Contributor

software-dov commented May 6, 2019

Setting the per-rpc deadline is sufficiently orthogonal to the purview of the RetryPolicy to merit a separate interface. Something like

class OperationDeadlinePolicy {
 public:
  virtual std::unique_ptr<OperationDeadlinePolicy> clone() const = 0;
  virtual std::chrono::system_clock::time_point Deadline() = 0;
};

template<typename Clock = DefaultClock>
class DefaultOperationDeadlinePolicy : public OperationDeadlinePolicy {
 public:
  template<typename Rep = int64_t, Period = std::milli>
  DefaultOperationDeadlinePolicy(std::chrono::duration<Rep, Period> rpc_duration,
                                                      Clock c = Clock{}) : 
                           duration_(std::chrono::duration_cast<std::chrono::milliseconds>(rpc_duration)), 
                           c_(std::move(c)) {}

  std::chrono::system_clock::time_point Deadline() override {
    return c_.now() + duration_;
  }

 private:
  std::chrono::milliseconds const duration_;
  Clock c_;
};
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant