Folly Futures to Python Asyncio Futures Bridge
[folly.git] / folly / python / test / simple.h
1 /*
2  * Copyright 2017-present Facebook, Inc.
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  */
16 #pragma once
17 #include <folly/futures/Future.h>
18 #include <folly/futures/Promise.h>
19 #include <cstdint>
20
21 namespace folly {
22 namespace python {
23 namespace test {
24
25 folly::Future<uint64_t> future_getValueX5(uint64_t val) {
26   folly::Promise<uint64_t> p;
27   auto f = p.getFuture();
28   p.setWith([val] {
29     if (val == 0) {
30       throw std::invalid_argument("0 is not allowed");
31     }
32     return val * 5;
33   });
34   return f;
35 }
36 }
37 }
38 }