From f628b0d6b06a56fb095eb4511c3889c6fd41731f Mon Sep 17 00:00:00 2001 From: Denis Blank Date: Sun, 9 Aug 2015 12:29:11 +0200 Subject: [PATCH] some changes --- .travis.yml | 2 +- CMakeLists.txt | 9 ++++---- mockup.cpp | 61 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8b4550c..b44b6a3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -32,4 +32,4 @@ install: script: - $CXX --version - make -j 4 - - ./continue_test + - ./ContinuableTest diff --git a/CMakeLists.txt b/CMakeLists.txt index e3ccb8e..cf2406c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,6 @@ if(MSVC) "which doesn't support all required C++11 features. " "(Visual Studio 2013 (Version >= 1800) is required!)") - message(STATUS "bad") endif() if(PLATFORM EQUAL 64) @@ -53,15 +52,15 @@ if(Boost_FOUND) endif() file(GLOB_RECURSE LIB_SOURCES include/*.cpp include/*.hpp include/*.h) -add_library(continue STATIC ${LIB_SOURCES}) +add_library(Continuable STATIC ${LIB_SOURCES}) include_directories(include dep/concurrentqueue) set(TEST_SOURCES test.cpp mockup.cpp) -add_executable(continue_test ${TEST_SOURCES}) +add_executable(ContinuableTest ${TEST_SOURCES}) -target_link_libraries(continue_test - continue +target_link_libraries(ContinuableTest + Continuable ${CMAKE_THREAD_LIBS_INIT} ) diff --git a/mockup.cpp b/mockup.cpp index bddf306..5b7a74a 100644 --- a/mockup.cpp +++ b/mockup.cpp @@ -81,30 +81,58 @@ Continuable<> mysql_query(std::string const& query) }); } -void test_mockup() +/// This mockup shows how to create a continuable from a functional object. +void create_continuable_mockup() { + /// Everything which accepts callbacks can be converted into a continuable. + /// Since nearly every async operation can be converted to use callbacks { - Continuable<> continuable = make_continuable([] + Continuable continuable = + make_continuable([](std::function&& /*TODO Find out if its better to use call by value*/ callback) { - return "hey"; + callback("my result"); }); } - Continuable<> c1 = make_continuable([] + // { - }); + // Accept params from previous continuable... + Continuable<> continuable = make_continuable([](int param1, int param2) + { + // ... and return the next continuable + return mysql_query("some query content"); + }); + } +} - Continuable<> c2 = make_continuable([] +/// This mockup shows how to chain multiple continuables together +void chain_continuable_mockup() +{ + // Best fitting functions { - }); + // Accept params from previous continuable... + Continuable<> continuable = make_continuable([](int param1, int param2) + { + // ... and return the next continuable + return mysql_query("some query content"); + }); + } - Continuable<> c3 = make_continuable([] + // { - }); + // Accept params from previous continuable... + Continuable<> continuable = make_continuable([](int param1, int param2) + { + // ... and return the next continuable + return mysql_query("some query content"); + }); + } +} - Continuable<> c4 = make_continuable([] - { - }); +/// This mockup shows the basic usage and features of continuables waiting for 2 http requests and a database query. +void final_mockup() +{ + Continuable<> c1, c2, c3, c4; (std::move(c1) && std::move(c2)) .then(http_request("https://github.com/") && @@ -118,6 +146,11 @@ void test_mockup() .then([](bool hasContent, std::string google, ResultSet user) { }); - - // Continuable<> c11 = || std::move(c3); +} + +void test_mockup() +{ + create_continuable_mockup(); + + final_mockup(); }