All Projects → Naios → awaitify

Naios / awaitify

Licence: BSL-1.0 license
Simple C++14 stackful await using boost's asio, future and coroutine2 (for testing purposes only)

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

awaitify offers simple C++14 stackful await functionality for testing purposes (this example isn't ready for production!) using boost's asio, future and coroutine2 and is implemented in less then 400 LOC.

awaitify is simple which makes it as easy to use await in C++ like in C# or Python.

Requirements

  • C++14 capable compiler (MSVC 2015+, Clang 3.6+, GCC 4.9+)
  • boost > 1.59 (requires boost::coroutine2) with following link libraries:
    • boost system
    • boost context
    • boost coroutine
    • boost thread

Examples

First of all include awaitify:

#include "awaitify/awaitify.hpp"

Start a new awaitable context through using:

awaitify([]
{
});

Wait for a future:

boost::future<int> sql_query(char const* sql);

awaitify([]
{
  // The value of the future is returned by the await expression
  int i = await sql_query("SELECT count(*) FROM users");
  // awaiting ready futures is possible
  return await boost::make_ready_future(true);
});

BUT: Never use await outside an awaitified expression!

AGAIN: This library is only meant for educational/testing purposes, never use it in a productional environment!

License

Copyright 2015-2016 Denis Blank <denis.blank at outlook dot com>
   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)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].