userver: userver/storages/redis/impl/transaction_subrequest_data.hpp Source File
Loading...
Searching...
No Matches
transaction_subrequest_data.hpp
1#pragma once
2
3#include <stdexcept>
4#include <string>
5#include <string_view>
6
7#include <userver/engine/future.hpp>
8#include <userver/storages/redis/request_data_base.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace storages::redis::impl {
13
14[[noreturn]] void ThrowTransactionNotStarted(std::string_view description);
15
16template <typename ReplyType>
17class TransactionSubrequestDataImpl final : public RequestDataBase<ReplyType> {
18 public:
19 TransactionSubrequestDataImpl(engine::Future<ReplyType> future)
20 : future_(std::move(future)) {}
21
22 void Wait() override { ThrowIfNotReady("Wait() for"); }
23
24 ReplyType Get(const std::string& /*request_description*/) override {
25 ThrowIfNotReady("Get()");
26 return future_.get();
27 }
28
29 ReplyPtr GetRaw() override {
30 throw std::logic_error("call TransactionSubrequestDataImpl::GetRaw()");
31 }
32
33 private:
34 void ThrowIfNotReady(std::string_view description) {
35 if (future_.wait_until(engine::Deadline::Passed()) !=
36 engine::FutureStatus::kReady) {
37 ThrowTransactionNotStarted(description);
38 }
39 }
40
41 engine::Future<ReplyType> future_;
42};
43
44} // namespace storages::redis::impl
45
46USERVER_NAMESPACE_END