As you can see here in this example UDP server, the run method will keep the application running forever. (tested)
So there is no need to use the work class as mentioned in the documentation
From boost documentation:
The work class is used to inform the io_service
when work starts and finishes. This ensures that the io_service
object's run()
function will not exit while work is underway, and that it does exit when there is no unfinished work remaining.
The work
class is deprecated and has been replaced by executor_work_guard
. Its purpose has been explained in the documentation:
Some applications may need to prevent an io_context object's
run()
call from returning when there is no more work to do. For example, the io_context may be being run in a background thread that is launched prior to the application's asynchronous operations. Therun()
call may be kept running by creating an object of typeboost::asio::executor_work_guard<io_context::executor_type>
[...]