GRPC Core
18.0.0
src
core
lib
iomgr
event_engine
promise.h
Go to the documentation of this file.
1
// Copyright 2021 The gRPC Authors
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
#ifndef GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H
15
#define GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H
16
#include <
grpc/support/port_platform.h
>
17
18
#include "
src/core/lib/gprpp/sync.h
"
19
20
namespace
grpc_event_engine
{
21
namespace
experimental {
22
28
template
<
typename
T>
29
class
Promise
{
30
public
:
31
T&
Get
() {
32
absl::MutexLock lock(&mu_);
33
cv_.Wait(&mu_);
34
return
val_;
35
}
36
void
Set
(T&& val) {
37
absl::MutexLock lock(&mu_);
38
val_ = std::move(val);
39
cv_.Signal();
40
}
41
42
private
:
43
absl::Mutex mu_;
44
absl::CondVar cv_;
45
T val_;
46
};
47
48
}
// namespace experimental
49
}
// namespace grpc_event_engine
50
51
#endif
// GRPC_CORE_LIB_IOMGR_EVENT_ENGINE_PROMISE_H
grpc_event_engine::experimental::Promise
A minimal promise implementation.
Definition:
promise.h:29
grpc_event_engine::experimental::Promise::Get
T & Get()
Definition:
promise.h:31
grpc_event_engine::experimental::Promise::Set
void Set(T &&val)
Definition:
promise.h:36
grpc_event_engine
Definition:
endpoint_config.h:24
sync.h
port_platform.h
Generated on Mon Sep 20 2021 00:00:00 for GRPC Core by
1.9.1