== delay Let's start with the simplest example possible: a simple delay. .example/delay.cpp [example] [source,cpp] ---- include::../../example/delay.cpp[tag=timer_example] ---- <1> The <> function defines an implicit `main` when used and is the easiest way to set up an environment to run asynchronous code. <2> Take the executor from the current coroutine promise. <3> Use an argument to set the timeout <4> Perform the wait by using <>. <5> Return a value that gets returned from the implicit main. In this example we use the <
> header, which provides us with a main coroutine if `co_main` is defined as above. This has a few advantages: - The environment get set up correctly (`executor` & `memory`) - asio is signaled that the context is single threaded - an `asio::signal_set` with `SIGINT` & `SIGTERM` is automatically connected to cancellations (i.e. `Ctrl+C` causes cancellations) This coroutine then has an executor in its promise (the promise the C++ name for a coroutine state. Not to be confused with <>) which we can obtain through the dummy-<>s in the <> namespace. We can then construct a timer and initiate the `async_wait` with <>. `cobalt` provides multiple ways to `co_await` to interact with asio, of which <> is the easiest.