template <typename R>
auto operator co_await(stlab::future<R> &&f)
(1)
auto operator co_await(stlab::future<void> &&f)
(2)

Creates a awaitable object on a given future.

  1. Creates a awaitable object on a given future of a move-only or copyable type R.

  2. Creates an awaitable object on a given future of type void.

This operator converts the given future to an awaitable objects for a coroutine.

Parameters

f

The future that shall be awaitable.

Return value

The awaitable object

Example 1


#define STLAB_FUTURE_COROUTINE_SUPPORT

#include <iostream>

#include <stlab/concurrency/default_executor.hpp>
#include <stlab/concurrency/future.hpp>
#include <stlab/concurrency/utility.hpp>


stlab::future<int> get_the_answer() { co_return 42; }

int main() {
	auto f = get_the_answer();

	std::cout << stlab::blocking_get(f) << '\n';
	return 0;
}

/*
    Result:

        42
*/