Skip to content

Commit cbfc4a1

Browse files
David-HaimLadence
andauthored
Version 0.1.2 (#46)
* deprecation of await_via and resume_via * addition of lazy_result * addition of resume_on * when_all + when_any rewrite * shared_result optimizations * examples rewrite Co-authored-by: Zakhar Karlin <zakhar.karlin11@gmail.com>
1 parent c9ae7d0 commit cbfc4a1

81 files changed

Lines changed: 2650 additions & 3896 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.16)
22

33
project(concurrencpp
4-
VERSION 0.1.1
4+
VERSION 0.1.2
55
LANGUAGES CXX)
66

77
include(cmake/coroutineOptions.cmake)
@@ -52,15 +52,19 @@ set(concurrencpp_headers
5252
include/concurrencpp/results/impl/producer_context.h
5353
include/concurrencpp/results/impl/result_state.h
5454
include/concurrencpp/results/impl/shared_result_state.h
55+
include/concurrencpp/results/impl/lazy_result_state.h
5556
include/concurrencpp/results/constants.h
5657
include/concurrencpp/results/make_result.h
5758
include/concurrencpp/results/promises.h
5859
include/concurrencpp/results/result.h
60+
include/concurrencpp/results/lazy_result.h
61+
include/concurrencpp/results/lazy_result_awaitable.h
5962
include/concurrencpp/results/shared_result.h
6063
include/concurrencpp/results/result_awaitable.h
6164
include/concurrencpp/results/shared_result_awaitable.h
6265
include/concurrencpp/results/result_fwd_declerations.h
6366
include/concurrencpp/results/when_result.h
67+
include/concurrencpp/results/resume_on.h
6468
include/concurrencpp/runtime/constants.h
6569
include/concurrencpp/runtime/runtime.h
6670
include/concurrencpp/threads/thread.h

README.md

Lines changed: 161 additions & 116 deletions
Large diffs are not rendered by default.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(10_regular_timer LANGUAGES CXX)
4+
5+
include(FetchContent)
6+
FetchContent_Declare(concurrencpp SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
7+
FetchContent_MakeAvailable(concurrencpp)
8+
9+
include(../../cmake/coroutineOptions.cmake)
10+
11+
add_executable(10_regular_timer source/main.cpp)
12+
13+
target_compile_features(10_regular_timer PRIVATE cxx_std_20)
14+
15+
target_link_libraries(10_regular_timer PRIVATE concurrencpp::concurrencpp)
16+
17+
target_coroutine_options(10_regular_timer)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "concurrencpp/concurrencpp.h"
2+
3+
#include <iostream>
4+
5+
using namespace std::chrono_literals;
6+
7+
int main() {
8+
concurrencpp::runtime runtime;
9+
std::atomic_size_t counter = 1;
10+
concurrencpp::timer timer = runtime.timer_queue()->make_timer(1500ms, 2000ms, runtime.thread_pool_executor(), [&] {
11+
const auto c = counter.fetch_add(1);
12+
std::cout << "timer was invoked for the " << c << "th time" << std::endl;
13+
});
14+
15+
std::cout << "timer due time (ms): " << timer.get_due_time().count() << std::endl;
16+
std::cout << "timer frequency (ms): " << timer.get_frequency().count() << std::endl;
17+
std::cout << "timer-associated executor : " << timer.get_executor()->name << std::endl;
18+
19+
std::this_thread::sleep_for(20s);
20+
21+
std::cout << "main thread cancelling timer" << std::endl;
22+
timer.cancel();
23+
24+
std::this_thread::sleep_for(10s);
25+
26+
return 0;
27+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(11_oneshot_time LANGUAGES CXX)
4+
5+
include(FetchContent)
6+
FetchContent_Declare(concurrencpp SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
7+
FetchContent_MakeAvailable(concurrencpp)
8+
9+
include(../../cmake/coroutineOptions.cmake)
10+
11+
add_executable(11_oneshot_time source/main.cpp)
12+
13+
target_compile_features(11_oneshot_time PRIVATE cxx_std_20)
14+
15+
target_link_libraries(11_oneshot_time PRIVATE concurrencpp::concurrencpp)
16+
17+
target_coroutine_options(11_oneshot_time)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include "concurrencpp/concurrencpp.h"
2+
3+
#include <iostream>
4+
5+
using namespace std::chrono_literals;
6+
7+
int main() {
8+
concurrencpp::runtime runtime;
9+
concurrencpp::timer timer = runtime.timer_queue()->make_one_shot_timer(3s, runtime.thread_executor(), [] {
10+
std::cout << "hello and goodbye" << std::endl;
11+
});
12+
13+
std::cout << "timer due time (ms): " << timer.get_due_time().count() << std::endl;
14+
std::cout << "timer frequency (ms): " << timer.get_frequency().count() << std::endl;
15+
std::cout << "timer-associated executor : " << timer.get_executor()->name << std::endl;
16+
17+
std::this_thread::sleep_for(4s);
18+
return 0;
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(12_delay_object LANGUAGES CXX)
4+
5+
include(FetchContent)
6+
FetchContent_Declare(concurrencpp SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
7+
FetchContent_MakeAvailable(concurrencpp)
8+
9+
include(../../cmake/coroutineOptions.cmake)
10+
11+
add_executable(12_delay_object source/main.cpp)
12+
13+
target_compile_features(12_delay_object PRIVATE cxx_std_20)
14+
15+
target_link_libraries(12_delay_object PRIVATE concurrencpp::concurrencpp)
16+
17+
target_coroutine_options(12_delay_object)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <iostream>
2+
3+
#include "concurrencpp/concurrencpp.h"
4+
5+
using namespace std::chrono_literals;
6+
7+
concurrencpp::null_result delayed_task(std::shared_ptr<concurrencpp::timer_queue> tq,
8+
std::shared_ptr<concurrencpp::thread_pool_executor> ex) {
9+
size_t counter = 1;
10+
11+
while (true) {
12+
std::cout << "task was invoked " << counter << " times." << std::endl;
13+
counter++;
14+
15+
co_await tq->make_delay_object(1500ms, ex);
16+
}
17+
}
18+
19+
int main() {
20+
concurrencpp::runtime runtime;
21+
delayed_task(runtime.timer_queue(), runtime.thread_pool_executor());
22+
23+
std::this_thread::sleep_for(10s);
24+
return 0;
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(1_hello_world LANGUAGES CXX)
4+
5+
include(FetchContent)
6+
FetchContent_Declare(concurrencpp SOURCE_DIR "${CMAKE_CURRENT_LIST_DIR}/../..")
7+
FetchContent_MakeAvailable(concurrencpp)
8+
9+
include(../../cmake/coroutineOptions.cmake)
10+
11+
add_executable(1_hello_world source/main.cpp)
12+
13+
target_compile_features(1_hello_world PRIVATE cxx_std_20)
14+
15+
target_link_libraries(1_hello_world PRIVATE concurrencpp::concurrencpp)
16+
17+
target_coroutine_options(1_hello_world)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "concurrencpp/concurrencpp.h"
2+
#include <iostream>
3+
4+
int main() {
5+
concurrencpp::runtime runtime;
6+
auto result = runtime.thread_executor()->submit([] {
7+
std::cout << "hello world" << std::endl;
8+
});
9+
10+
result.get();
11+
return 0;
12+
}

0 commit comments

Comments
 (0)