Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ CMakeFiles
Makefile
*.cmake
CMakeCache.txt
.cache
compile_commands.json
2 changes: 1 addition & 1 deletion Chapter_09/9x02-executor_work_guard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void background_task(boost::asio::io_context& io_context) {
// Waiting for 2 seconds before posting work
std::this_thread::sleep_for(2s);
std::cout << "Posting a background task.\n";
io_context.post([]() { std::cout << "Background task completed!\n"; });
boost::asio::post( io_context, []() { std::cout << "Background task completed!\n"; });
}

int main() {
Expand Down
5 changes: 3 additions & 2 deletions Chapter_09/9x04-post_and_dispatch.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include <boost/asio.hpp>
#include <boost/asio/dispatch.hpp>
#include <iostream>

int main() {
boost::asio::io_context io_context;

io_context.post([] { std::cout << "This will always run asynchronously.\n"; });
boost::asio::post( io_context, [] { std::cout << "This will always run asynchronously.\n"; });

io_context.dispatch([] { std::cout << "This might run immediately or be queued.\n"; });
boost::asio::dispatch(io_context, [] { std::cout << "This might run immediately or be queued.\n"; });

io_context.run();
return 0;
Expand Down
2 changes: 1 addition & 1 deletion Chapter_09/9x06-exception_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void my_handler() {
}

void post_handler(boost::asio::io_context& io_context) {
io_context.post(my_handler);
boost::asio::post( io_context, my_handler);
}

int main() {
Expand Down
4 changes: 2 additions & 2 deletions Chapter_09/9x08-multithreaded_io_context_main_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
void long_running_task(boost::asio::io_context& io_context, int task_duration) {
std::cout << "Background task started: Duration = " << task_duration << " seconds.\n";
std::this_thread::sleep_for(std::chrono::seconds(task_duration));
io_context.post([&io_context]() {
boost::asio::post( io_context, [&io_context]() {
std::cout << "Background task completed.\n";
io_context.stop();
});
Expand All @@ -16,7 +16,7 @@ int main() {

auto work_guard = boost::asio::make_work_guard(io_context);

io_context.post([&io_context]() {
boost::asio::post( io_context, [&io_context]() {
std::thread t(long_running_task, std::ref(io_context), 2);
std::cout << "Detaching thread" << std::endl;
t.detach();
Expand Down
2 changes: 1 addition & 1 deletion Chapter_09/9x18-explicit_strands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Logger {

void log(const std::string message) {
//strand_.post(std::bind(&Logger::do_log, this, message));
strand_.post([this, message]() { do_log(message); });
boost::asio::post( strand_, [this, message]() { do_log(message); });
}

private:
Expand Down
2 changes: 2 additions & 0 deletions Chapter_11/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BINARY_DIR}/Chapter_11)

find_package( spdlog REQUIRED )

# Create executable for each cpp file
file(GLOB SOURCES "*.cpp")
foreach(SOURCE ${SOURCES})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using namespace std::chrono_literals;

void asyncFunc(boost::asio::io_context& io_context, std::function<void(int)> callback) {
io_context.post([callback]() {
boost::asio::post( io_context, [callback]() {
std::this_thread::sleep_for(100ms);
callback(42);
});
Expand Down