// Based on the Boost.Cobalt documentation examples.
// Copyright (c) 2025 Klemens D. Morgenstern
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/cobalt/main.hpp>
#include <boost/cobalt/io/sleep.hpp>
#include <chrono>
#include <iostream>

namespace cobalt = boost::cobalt;

cobalt::main co_main(int, char *[])
{
  const auto start = std::chrono::steady_clock::now();
  co_await cobalt::io::sleep(std::chrono::milliseconds(50));
  const auto elapsed = std::chrono::steady_clock::now() - start;

  std::cout << "slept for "
            << std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count()
            << "ms" << std::endl;
  co_return elapsed >= std::chrono::milliseconds(50) ? 0 : 1;
}
