From 622890fc2cd0d701105748237aa7377dbb435f01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Mon, 12 Aug 2024 13:59:09 +0200 Subject: [PATCH 01/11] remove experimental warning from using_coroutines.md --- docpages/example_programs/using_coroutines.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docpages/example_programs/using_coroutines.md b/docpages/example_programs/using_coroutines.md index 8e239c3f3e..f51a7d7282 100644 --- a/docpages/example_programs/using_coroutines.md +++ b/docpages/example_programs/using_coroutines.md @@ -1,7 +1,5 @@ \page using-coroutines Using Coroutines -\include{doc} coro_warn.dox - One of the most anticipated features of C++20 is the addition of coroutines: in short, they are functions that can be paused while waiting for data and resumed when that data is ready. They make asynchronous programs much easier to write, but they do come with additional dangers and subtleties. * \subpage coro-introduction From b6083d0df5556229b594b7c77200a0d2fe911006 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:00:35 +0200 Subject: [PATCH 02/11] remove experimental warning from coro_simple_commands.md --- .../example_programs/using_coroutines/coro_simple_commands.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docpages/example_programs/using_coroutines/coro_simple_commands.md b/docpages/example_programs/using_coroutines/coro_simple_commands.md index 0ec97b8437..696da188a7 100644 --- a/docpages/example_programs/using_coroutines/coro_simple_commands.md +++ b/docpages/example_programs/using_coroutines/coro_simple_commands.md @@ -1,7 +1,5 @@ \page coro-simple-commands Making simple commands -\include{doc} coro_warn.dox - ### Several steps in one \note The next example assumes you are already familiar with how to use \ref firstbot "slash commands", \ref slashcommands "parameters", and \ref discord-application-command-file-upload "sending files through a command". From efafb6fbde1156123c3bb61428f3f9e615ab0912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:01:05 +0200 Subject: [PATCH 03/11] remove experimental warning from awaiting_events.md --- docpages/example_programs/using_coroutines/awaiting_events.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docpages/example_programs/using_coroutines/awaiting_events.md b/docpages/example_programs/using_coroutines/awaiting_events.md index 45b7a4dcfc..51ccb6ae40 100644 --- a/docpages/example_programs/using_coroutines/awaiting_events.md +++ b/docpages/example_programs/using_coroutines/awaiting_events.md @@ -1,7 +1,5 @@ \page awaiting-events Waiting for events -\include{doc} coro_warn.dox - D++ makes it possible to await events: simple use `co_await` on any of the event routers, such as \ref dpp::cluster::on_message_create "on_message_create", and your coroutine will be suspended until the next event fired by this event router. You can also `co_await` the return of an event router's \ref dpp::event_router_t::when "when()" method while passing it a predicate function object, it will only resume your coroutine when the predicate returns true. Be aware that your coroutine is attached to the event router only when you call `co_await` and not before, and will be detached as it is resumed. \note When the event router resumes your coroutine, it will give you __a reference to the event object__. This will likely mean it will be destroyed after your next co_await, make sure to save it in a local variable if you need it for longer. From d3cff222e4029fe722311c0b82aadb3da74d0437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:01:30 +0200 Subject: [PATCH 04/11] remove experimental warning from expiring_buttons.md --- docpages/example_programs/using_coroutines/expiring_buttons.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docpages/example_programs/using_coroutines/expiring_buttons.md b/docpages/example_programs/using_coroutines/expiring_buttons.md index f07234714e..23492a8673 100644 --- a/docpages/example_programs/using_coroutines/expiring_buttons.md +++ b/docpages/example_programs/using_coroutines/expiring_buttons.md @@ -1,7 +1,5 @@ \page expiring-buttons Making expiring buttons with when_any -\include{doc} coro_warn.dox - In the last example we've explored how to \ref awaiting-events "await events" using coroutines, we ran into the problem of the coroutine waiting forever if the button was never clicked. Wouldn't it be nice if we could add an "or" to our algorithm, for example wait for the button to be clicked *or* for a timer to expire? I'm glad you asked! D++ offers \ref dpp::when_any "when_any" which allows exactly that. It is a templated class that can take any number of awaitable objects and can be `co_await`-ed itself, will resume when the __first__ awaitable completes and return a \ref dpp::when_any::result "result" object that allows to retrieve which awaitable completed as well as its result, in a similar way as std::variant. \include{cpp} coro_expiring_buttons.cpp From 540bd2fe796a03e75e02ab6be74d341fb5387ed8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Mon, 12 Aug 2024 14:10:36 +0200 Subject: [PATCH 05/11] Update DPP_CORO comment in CMakeLists.txt Remove "experimental" notice from DPP_CORO's comment. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f2e7a58f2d..874453a74c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ option(RUN_LDCONFIG "Run ldconfig after installation" ON) option(DPP_INSTALL "Generate the install target" ON) option(DPP_BUILD_TEST "Build the test program" ON) option(DPP_NO_VCPKG "No VCPKG" OFF) -option(DPP_CORO "Experimental support for C++20 coroutines" OFF) +option(DPP_CORO "Support for C++20 coroutines" OFF) option(DPP_FORMATTERS "Support for C++20 formatters" OFF) option(DPP_USE_EXTERNAL_JSON "Use an external installation of nlohmann::json" OFF) option(DPP_USE_PCH "Use precompiled headers to speed up compilation" OFF) From 074d09364b2fdde88c39a679b2bdd8b279a51a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Wed, 4 Sep 2024 16:59:44 +0200 Subject: [PATCH 06/11] remove experimental warning from library/CMakeLists.txt --- library/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 00b2a8b651..bc61c77723 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -289,7 +289,7 @@ if(HAVE_PTHREAD_SETNAME_NP) endif() if(DPP_CORO) - message("-- ${Yellow}Enabled experimental coroutine feature${ColourReset}") + message("-- ${Yellow}Enabled coroutine feature${ColourReset}") set(CMAKE_CXX_STANDARD 20) target_compile_features(dpp PUBLIC cxx_std_20) if(WIN32 AND NOT MINGW AND NOT DPP_CLANG_CL) From c08dcfed2e62ee28a131dc6d53f717566f1bec15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= Date: Wed, 4 Sep 2024 17:23:30 +0200 Subject: [PATCH 07/11] Revert "remove experimental warning from using_coroutines.md" This reverts commit 622890fc2cd0d701105748237aa7377dbb435f01. --- docpages/example_programs/using_coroutines.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docpages/example_programs/using_coroutines.md b/docpages/example_programs/using_coroutines.md index f51a7d7282..8e239c3f3e 100644 --- a/docpages/example_programs/using_coroutines.md +++ b/docpages/example_programs/using_coroutines.md @@ -1,5 +1,7 @@ \page using-coroutines Using Coroutines +\include{doc} coro_warn.dox + One of the most anticipated features of C++20 is the addition of coroutines: in short, they are functions that can be paused while waiting for data and resumed when that data is ready. They make asynchronous programs much easier to write, but they do come with additional dangers and subtleties. * \subpage coro-introduction From d6bdec82d9c523905d5eecf027069b37494a719d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= Date: Wed, 4 Sep 2024 17:23:33 +0200 Subject: [PATCH 08/11] Revert "remove experimental warning from coro_simple_commands.md" This reverts commit b6083d0df5556229b594b7c77200a0d2fe911006. --- .../example_programs/using_coroutines/coro_simple_commands.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docpages/example_programs/using_coroutines/coro_simple_commands.md b/docpages/example_programs/using_coroutines/coro_simple_commands.md index 696da188a7..0ec97b8437 100644 --- a/docpages/example_programs/using_coroutines/coro_simple_commands.md +++ b/docpages/example_programs/using_coroutines/coro_simple_commands.md @@ -1,5 +1,7 @@ \page coro-simple-commands Making simple commands +\include{doc} coro_warn.dox + ### Several steps in one \note The next example assumes you are already familiar with how to use \ref firstbot "slash commands", \ref slashcommands "parameters", and \ref discord-application-command-file-upload "sending files through a command". From cb8d5aeb623b42fc8ab46dcd5f4259d2757bb2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= Date: Wed, 4 Sep 2024 17:23:40 +0200 Subject: [PATCH 09/11] Revert "remove experimental warning from awaiting_events.md" This reverts commit efafb6fbde1156123c3bb61428f3f9e615ab0912. --- docpages/example_programs/using_coroutines/awaiting_events.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docpages/example_programs/using_coroutines/awaiting_events.md b/docpages/example_programs/using_coroutines/awaiting_events.md index 51ccb6ae40..45b7a4dcfc 100644 --- a/docpages/example_programs/using_coroutines/awaiting_events.md +++ b/docpages/example_programs/using_coroutines/awaiting_events.md @@ -1,5 +1,7 @@ \page awaiting-events Waiting for events +\include{doc} coro_warn.dox + D++ makes it possible to await events: simple use `co_await` on any of the event routers, such as \ref dpp::cluster::on_message_create "on_message_create", and your coroutine will be suspended until the next event fired by this event router. You can also `co_await` the return of an event router's \ref dpp::event_router_t::when "when()" method while passing it a predicate function object, it will only resume your coroutine when the predicate returns true. Be aware that your coroutine is attached to the event router only when you call `co_await` and not before, and will be detached as it is resumed. \note When the event router resumes your coroutine, it will give you __a reference to the event object__. This will likely mean it will be destroyed after your next co_await, make sure to save it in a local variable if you need it for longer. From d15f12b7cc52b5b8e883bfae3b1239792d953408 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= Date: Wed, 4 Sep 2024 17:23:42 +0200 Subject: [PATCH 10/11] Revert "remove experimental warning from expiring_buttons.md" This reverts commit d3cff222e4029fe722311c0b82aadb3da74d0437. --- docpages/example_programs/using_coroutines/expiring_buttons.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docpages/example_programs/using_coroutines/expiring_buttons.md b/docpages/example_programs/using_coroutines/expiring_buttons.md index 23492a8673..f07234714e 100644 --- a/docpages/example_programs/using_coroutines/expiring_buttons.md +++ b/docpages/example_programs/using_coroutines/expiring_buttons.md @@ -1,5 +1,7 @@ \page expiring-buttons Making expiring buttons with when_any +\include{doc} coro_warn.dox + In the last example we've explored how to \ref awaiting-events "await events" using coroutines, we ran into the problem of the coroutine waiting forever if the button was never clicked. Wouldn't it be nice if we could add an "or" to our algorithm, for example wait for the button to be clicked *or* for a timer to expire? I'm glad you asked! D++ offers \ref dpp::when_any "when_any" which allows exactly that. It is a templated class that can take any number of awaitable objects and can be `co_await`-ed itself, will resume when the __first__ awaitable completes and return a \ref dpp::when_any::result "result" object that allows to retrieve which awaitable completed as well as its result, in a similar way as std::variant. \include{cpp} coro_expiring_buttons.cpp From 7d32b2636042f89fd6fbed9d2e1d2b34846c9ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DJ=3A=3A=C3=96tzi?= <58144390+DJOetzi@users.noreply.github.com> Date: Wed, 4 Sep 2024 17:33:54 +0200 Subject: [PATCH 11/11] remove experimental warning from coro_warn.dox --- docpages/include/coro_warn.dox | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docpages/include/coro_warn.dox b/docpages/include/coro_warn.dox index 2bf9097b71..5710006205 100644 --- a/docpages/include/coro_warn.dox +++ b/docpages/include/coro_warn.dox @@ -1 +1 @@ -\warning D++ Coroutines are a very new feature and are currently only supported by D++ on g++ 13, clang/LLVM 14, and MSVC 19.37 or above. Additionally, D++ must be built with the CMake option DPP_CORO, and your program must both define the macro DPP_CORO and use C++20 or above. The feature is experimental and may have bugs or even crashes, please report any to GitHub Issues or to our Discord Server. +\warning D++ Coroutines are a very new feature and are currently only supported by D++ on g++ 13, clang/LLVM 14, and MSVC 19.37 or above. Additionally, D++ must be built with the CMake option DPP_CORO, and your program must both define the macro DPP_CORO and use C++20 or above.