cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
call_promise.h.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <chrono>
23#include <memory>
24#include <utility>
25
29
31
36public:
42 explicit CallPromise(std::chrono::steady_clock::time_point deadline)
43 : future_(std::make_shared<CallFutureImpl>(deadline)) {}
44
50 void set(messages::CallResult result) { future_->set(std::move(result)); }
51
57 void set(const Status& error) { future_->set(error); }
58
64 [[nodiscard]] std::shared_ptr<CallFutureImpl> future() const noexcept {
65 return future_;
66 }
67
68private:
70 std::shared_ptr<CallFutureImpl> future_;
71};
72
73} // namespace msgpack_rpc::clients::impl
Definition of CallFutureImpl class.
Definition of CallResult class.
Class of internal implementation of future objects to get results of RPCs asynchronously.
std::shared_ptr< CallFutureImpl > future_
Future.
void set(messages::CallResult result)
Set a result.
std::shared_ptr< CallFutureImpl > future() const noexcept
Get the future.
void set(const Status &error)
Set an error.
CallPromise(std::chrono::steady_clock::time_point deadline)
Constructor.
Class of statuses.
Definition status.h:34
Class of results of methods.
Definition call_result.h:35
Namespace of internal implementations.
STL namespace.
Definition of Status class.