Skip to content

nevoeitan/AwaitableFuture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AwaitableFuture

This project shows how std::future can be used with co_await. In this implementation the await for the result happens in the backgronud in a threadpool.

Usage

To use the code include AwaitableFuture.hpp

Example

Here is an exmaple from main.cpp:

std::future<int> func()
{
    auto res = co_await std::async([]
            {
                std::this_thread::sleep_for(std::chrono::seconds(3));

                return 30;
            });

    co_return res;
}

Output of main.cpp:

Not ready
Not ready
Not ready
30

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published