-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a534284
Showing
35 changed files
with
5,119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Prerequisites | ||
*.d | ||
|
||
# Compiled Object files | ||
*.slo | ||
*.lo | ||
*.o | ||
*.obj | ||
|
||
# Precompiled Headers | ||
*.gch | ||
*.pch | ||
|
||
# Compiled Dynamic libraries | ||
*.so | ||
*.dylib | ||
*.dll | ||
|
||
# Fortran module files | ||
*.mod | ||
*.smod | ||
|
||
# Compiled Static libraries | ||
*.lai | ||
*.la | ||
*.a | ||
*.lib | ||
|
||
# Executables | ||
*.exe | ||
*.out | ||
*.app | ||
|
||
# Settings and Build/Testing directories | ||
.vscode/ | ||
build/ | ||
Testing/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
project(thousandeyes-futures VERSION 0.1 LANGUAGES CXX) | ||
|
||
add_library(thousandeyes-futures INTERFACE) | ||
add_library(thousandeyes::futures ALIAS thousandeyes-futures) | ||
|
||
target_include_directories(thousandeyes-futures | ||
INTERFACE | ||
${PROJECT_SOURCE_DIR}/include | ||
) | ||
|
||
target_sources(thousandeyes-futures INTERFACE | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/Default.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/DefaultExecutor.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/Executor.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/PollingExecutor.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/TimedWaitable.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/Waitable.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/all.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/then.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/util.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithChaining.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithContainer.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithContinuation.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithForwarding.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithIterators.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/FutureWithTuple.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/InvokerWithNewThread.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/InvokerWithSingleThread.h | ||
${PROJECT_SOURCE_DIR}/include/thousandeyes/futures/detail/typetraits.h | ||
) | ||
|
||
if(THOUSANDEYES_FUTURES_BUILD_EXAMPLES) | ||
add_subdirectory(examples) | ||
endif() | ||
|
||
if(THOUSANDEYES_FUTURES_BUILD_TESTS) | ||
enable_testing() | ||
add_subdirectory(tests) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Look for the header files. | ||
find_path(thousandeyes-futures_INCLUDE_DIR | ||
NAMES thousandeyes/futures/then.h | ||
HINTS "${thousandeyes-futures_ROOT}/include") | ||
mark_as_advanced(thousandeyes-futures_INCLUDE_DIR) | ||
|
||
include(FindPackageHandleStandardArgs) | ||
|
||
find_package_handle_standard_args(thousandeyes-futures | ||
REQUIRED_VARS thousandeyes-futures_INCLUDE_DIR) | ||
|
||
if (thousandeyes-futures_FOUND) | ||
set(thousandeyes-futures_INCLUDE_DIRS ${thousandeyes-futures_INCLUDE_DIR}) | ||
|
||
# Define imported targets | ||
add_library(thousandeyes::futures INTERFACE IMPORTED) | ||
set_target_properties(thousandeyes::futures PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES "${thousandeyes-futures_INCLUDE_DIRS}") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 ThousandEyes, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from conans import ConanFile, CMake | ||
|
||
class ThousandEyesFuturesConan(ConanFile): | ||
name = "thousandeyes-futures" | ||
version = "0.1" | ||
exports_sources = "include/*", "FindThousandEyesFutures.cmake" | ||
no_copy_source = True | ||
short_paths = True | ||
|
||
def package(self): | ||
self.copy("*.h") | ||
self.copy("FindThousandEyesFutures.cmake", dst=".", src=".") | ||
|
||
def package_id(self): | ||
self.info.header_only() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.11) | ||
|
||
find_package(Threads) | ||
|
||
function(add_example _file) | ||
get_filename_component(test_name ${_file} NAME_WE) | ||
set(_target example-${test_name}) | ||
|
||
add_executable(${_target} ${_file}) | ||
|
||
target_link_libraries(${_target} | ||
PRIVATE ${CMAKE_THREAD_LIBS_INIT} | ||
PRIVATE thousandeyes::futures) | ||
|
||
set_target_properties(${_target} PROPERTIES CXX_STANDARD 14) | ||
endfunction(add_example) | ||
|
||
add_example(chaining.cpp) | ||
add_example(conversion.cpp) | ||
add_example(executors.cpp) | ||
add_example(recursive.cpp) | ||
add_example(sum.cpp) | ||
add_example(timeout.cpp) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright 2019 ThousandEyes, Inc. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* | ||
* @author Giannis Georgalis, https://github.com/ggeorgalis | ||
*/ | ||
|
||
#include <functional> | ||
#include <future> | ||
#include <iostream> | ||
#include <string> | ||
#include <memory> | ||
|
||
#include <thousandeyes/futures/DefaultExecutor.h> | ||
#include <thousandeyes/futures/then.h> | ||
|
||
using namespace std; | ||
using namespace std::chrono; | ||
using namespace thousandeyes::futures; | ||
|
||
namespace { | ||
|
||
template<class T> | ||
future<T> getValueAsync(const T& value) | ||
{ | ||
return async(launch::async, [value]() { | ||
return value; | ||
}); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
auto executor = make_shared<DefaultExecutor>(milliseconds(10)); | ||
Default<Executor>::Setter execSetter(executor); | ||
|
||
auto f = then(getValueAsync(1821), [](future<int> f) { | ||
auto first = to_string(f.get()); | ||
return then(getValueAsync(string("1822")), [first](future<string> f) { | ||
auto second = f.get(); | ||
return then(getValueAsync(1823), [first, second](future<int> f) { | ||
return first + '_' + second + '_' + to_string(f.get()); | ||
}); | ||
}); | ||
}); | ||
|
||
string result = f.get(); | ||
|
||
cout << "Got result: " << result << endl; | ||
|
||
executor->stop(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2019 ThousandEyes, Inc. | ||
* | ||
* Use of this source code is governed by an MIT-style | ||
* license that can be found in the LICENSE file or at | ||
* https://opensource.org/licenses/MIT. | ||
* | ||
* @author Giannis Georgalis, https://github.com/ggeorgalis | ||
*/ | ||
|
||
#include <functional> | ||
#include <future> | ||
#include <iostream> | ||
#include <string> | ||
#include <memory> | ||
|
||
#include <thousandeyes/futures/DefaultExecutor.h> | ||
#include <thousandeyes/futures/then.h> | ||
|
||
using namespace std; | ||
using namespace std::chrono; | ||
using namespace thousandeyes::futures; | ||
|
||
namespace { | ||
|
||
template<class T> | ||
future<T> getValueAsync(const T& value) | ||
{ | ||
return async(launch::async, [value]() { | ||
return value; | ||
}); | ||
} | ||
|
||
} // namespace | ||
|
||
int main(int argc, const char* argv[]) | ||
{ | ||
auto executor = make_shared<DefaultExecutor>(milliseconds(10)); | ||
Default<Executor>::Setter execSetter(executor); | ||
|
||
auto f = then(getValueAsync(1821), [](future<int> f) { | ||
return to_string(f.get()); | ||
}); | ||
|
||
string result = f.get(); | ||
|
||
cout << "Got result: " << result << endl; | ||
|
||
executor->stop(); | ||
} |
Oops, something went wrong.