cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
call.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
33
35
39class Call {
40public:
47 Call(const std::shared_ptr<executors::IExecutor>& executor,
48 std::chrono::steady_clock::time_point deadline)
49 : promise_(deadline),
50 timeout_timer_(executor, executors::OperationType::CALLBACK) {}
51
59 template <typename OnTimeout>
60 void set_timeout(std::chrono::steady_clock::time_point deadline,
61 OnTimeout&& on_timeout) {
62 timeout_timer_.async_sleep_until(
63 deadline, std::forward<OnTimeout>(on_timeout));
64 }
65
71 [[nodiscard]] std::shared_ptr<CallFutureImpl> future() const noexcept {
72 return promise_.future();
73 }
74
80 void set(const messages::CallResult& result) { promise_.set(result); }
81
87 void set(const Status& error) { promise_.set(error); }
88
89private:
92
95};
96
97} // namespace msgpack_rpc::clients::impl
Definition of CallFutureImpl class.
Definition of CallPromise class.
Definition of CallResult class.
Class to set results of RPCs.
void set_timeout(std::chrono::steady_clock::time_point deadline, OnTimeout &&on_timeout)
Set timeout.
Definition call.h:60
std::shared_ptr< CallFutureImpl > future() const noexcept
Get the future object to set and get the result of this RPC.
Definition call.h:71
CallPromise promise_
Object to set the result of this RPC.
Definition call.h:91
Call(const std::shared_ptr< executors::IExecutor > &executor, std::chrono::steady_clock::time_point deadline)
Constructor.
Definition call.h:47
void set(const messages::CallResult &result)
Set the result.
Definition call.h:80
void set(const Status &error)
Set an error.
Definition call.h:87
executors::Timer timeout_timer_
Timer of timeout.
Definition call.h:94
Class of statuses.
Definition status.h:34
Class of timers to call functions later.
Definition timer.h:37
Class of results of methods.
Definition call_result.h:35
Definition of IExecutor class.
Namespace of internal implementations.
Namespace of executors to process asynchronous tasks.
Definition of OperationType enumeration.
Definition of Status class.
Definition of Timer class.