asio coroutine timer

I am being confused the asio::timer coroutine does not work if I modify the timer in another coroutine:

The "Leave foo" never reached:

Enter foo
Enter bar
Leave bar
The End

static asio::awaitable<void> foo(asio::steady_timer& timer)
cout << "Enter foo" << endl;
co_await timer.async_wait(asio::use_awaitable);
cout << "Leave foo" << endl;

static asio::awaitable<void> bar(asio::steady_timer& timer)
cout << "Enter bar" << endl;
sleep(2); // wait a little for asio::io_service::run to be executed
cout << "Leave bar" << endl;

int main()
asio::io_context ioService;
asio::steady_timer timer(ioService);

asio::co_spawn(ioService, foo(timer), asio::detached);
asio::co_spawn(ioService, bar(timer), asio::detached);;
std::printf("The End\n");
return 0;
I know very little about coroutines so excuse me if I say something stupid, but in foo you set the timer to expire after max duration? Isn't that a VERY long time? If async_wait will wait until that duration has passed, and there is nothing else that will make it return before that, then it seems to me like it would be stuck there for a very long time.
The timer will expire in function bar:

Yes it will. If I set the timer a callback, it would be executed. But in this case, I set it "asio::use_awaitable", the coroutine will NOT be resumed.
Registered users can post here. Sign in or register to post.