mirror of
https://github.com/Naios/continuable.git
synced 2025-12-07 01:06:44 +08:00
some changes
This commit is contained in:
parent
e7ffe69fa7
commit
f628b0d6b0
@ -32,4 +32,4 @@ install:
|
|||||||
script:
|
script:
|
||||||
- $CXX --version
|
- $CXX --version
|
||||||
- make -j 4
|
- make -j 4
|
||||||
- ./continue_test
|
- ./ContinuableTest
|
||||||
|
|||||||
@ -11,7 +11,6 @@ if(MSVC)
|
|||||||
"which doesn't support all required C++11 features. "
|
"which doesn't support all required C++11 features. "
|
||||||
"(Visual Studio 2013 (Version >= 1800) is required!)")
|
"(Visual Studio 2013 (Version >= 1800) is required!)")
|
||||||
|
|
||||||
message(STATUS "bad")
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(PLATFORM EQUAL 64)
|
if(PLATFORM EQUAL 64)
|
||||||
@ -53,15 +52,15 @@ if(Boost_FOUND)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
file(GLOB_RECURSE LIB_SOURCES include/*.cpp include/*.hpp include/*.h)
|
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)
|
include_directories(include dep/concurrentqueue)
|
||||||
|
|
||||||
set(TEST_SOURCES test.cpp mockup.cpp)
|
set(TEST_SOURCES test.cpp mockup.cpp)
|
||||||
|
|
||||||
add_executable(continue_test ${TEST_SOURCES})
|
add_executable(ContinuableTest ${TEST_SOURCES})
|
||||||
|
|
||||||
target_link_libraries(continue_test
|
target_link_libraries(ContinuableTest
|
||||||
continue
|
Continuable
|
||||||
${CMAKE_THREAD_LIBS_INIT}
|
${CMAKE_THREAD_LIBS_INIT}
|
||||||
)
|
)
|
||||||
|
|||||||
61
mockup.cpp
61
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</*std::string*/> continuable =
|
||||||
|
make_continuable([](std::function<void(std::string)>&& /*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))
|
(std::move(c1) && std::move(c2))
|
||||||
.then(http_request("https://github.com/") &&
|
.then(http_request("https://github.com/") &&
|
||||||
@ -118,6 +146,11 @@ void test_mockup()
|
|||||||
.then([](bool hasContent, std::string google, ResultSet user)
|
.then([](bool hasContent, std::string google, ResultSet user)
|
||||||
{
|
{
|
||||||
});
|
});
|
||||||
|
}
|
||||||
// Continuable<> c11 = || std::move(c3);
|
|
||||||
|
void test_mockup()
|
||||||
|
{
|
||||||
|
create_continuable_mockup();
|
||||||
|
|
||||||
|
final_mockup();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user