Commit b1f03d3b authored by Xavier Thompson's avatar Xavier Thompson

Rename Future into Async

parent 522f9cf2
#ifndef TYPON_CORE_FUTURE_HPP_INCLUDED #ifndef TYPON_CORE_ASYNC_HPP_INCLUDED
#define TYPON_CORE_FUTURE_HPP_INCLUDED #define TYPON_CORE_ASYNC_HPP_INCLUDED
#include <coroutine> #include <coroutine>
#include <memory> #include <memory>
...@@ -15,7 +15,7 @@ namespace typon ...@@ -15,7 +15,7 @@ namespace typon
{ {
template <typename T> template <typename T>
struct Future struct Async
{ {
using value_type = T; using value_type = T;
...@@ -26,7 +26,7 @@ namespace typon ...@@ -26,7 +26,7 @@ namespace typon
}; };
template <typename Promise> template <typename Promise>
Future(std::coroutine_handle<Promise> coroutine, bool ready) Async(std::coroutine_handle<Promise> coroutine, bool ready)
{ {
if (ready) if (ready)
{ {
...@@ -39,7 +39,7 @@ namespace typon ...@@ -39,7 +39,7 @@ namespace typon
} }
} }
Future(Future && other) noexcept(std::is_nothrow_move_constructible_v<T>) Async(Async && other) noexcept(std::is_nothrow_move_constructible_v<T>)
{ {
_result = other._result; _result = other._result;
if (!_result) if (!_result)
...@@ -48,12 +48,12 @@ namespace typon ...@@ -48,12 +48,12 @@ namespace typon
} }
} }
Future& operator=(Future && other) Async& operator=(Async && other)
noexcept(std::is_nothrow_move_constructible_v<T>) noexcept(std::is_nothrow_move_constructible_v<T>)
{ {
if (this != &other) if (this != &other)
{ {
Future old { std::move(*this) }; Async old { std::move(*this) };
_result = other._result; _result = other._result;
if (!_result) if (!_result)
{ {
...@@ -63,7 +63,7 @@ namespace typon ...@@ -63,7 +63,7 @@ namespace typon
return *this; return *this;
} }
~Future() ~Async()
{ {
if (!_result) if (!_result)
{ {
...@@ -84,7 +84,7 @@ namespace typon ...@@ -84,7 +84,7 @@ namespace typon
template <typename T> template <typename T>
requires requires { sizeof(T); } && (sizeof(T) > 2 * sizeof(void*)) requires requires { sizeof(T); } && (sizeof(T) > 2 * sizeof(void*))
struct Future<T> struct Async<T>
{ {
using value_type = T; using value_type = T;
...@@ -92,7 +92,7 @@ namespace typon ...@@ -92,7 +92,7 @@ namespace typon
std::coroutine_handle<> _coroutine; std::coroutine_handle<> _coroutine;
template <typename Promise> template <typename Promise>
Future(std::coroutine_handle<Promise> coroutine, bool ready) Async(std::coroutine_handle<Promise> coroutine, bool ready)
{ {
_result = &(coroutine.promise()); _result = &(coroutine.promise());
if (ready) if (ready)
...@@ -105,22 +105,22 @@ namespace typon ...@@ -105,22 +105,22 @@ namespace typon
} }
} }
Future(const Future &) = delete; Async(const Async &) = delete;
Future& operator=(const Future &) = delete; Async& operator=(const Async &) = delete;
Future(Future && other) noexcept Async(Async && other) noexcept
: _result(other._result) : _result(other._result)
, _coroutine(std::exchange(other._coroutine, nullptr)) , _coroutine(std::exchange(other._coroutine, nullptr))
{} {}
Future& operator=(Future && other) noexcept Async& operator=(Async && other) noexcept
{ {
std::swap(_coroutine, other._coroutine); std::swap(_coroutine, other._coroutine);
std::swap(_result, other._result); std::swap(_result, other._result);
return *this; return *this;
} }
~Future() ~Async()
{ {
if (_coroutine) if (_coroutine)
{ {
...@@ -137,7 +137,7 @@ namespace typon ...@@ -137,7 +137,7 @@ namespace typon
template <typename T> template <typename T>
requires std::is_trivially_copyable_v<T> requires std::is_trivially_copyable_v<T>
struct Future<T> struct Async<T>
{ {
using value_type = T; using value_type = T;
...@@ -148,7 +148,7 @@ namespace typon ...@@ -148,7 +148,7 @@ namespace typon
}; };
template <typename Promise> template <typename Promise>
Future(std::coroutine_handle<Promise> coroutine, bool ready) Async(std::coroutine_handle<Promise> coroutine, bool ready)
{ {
if (ready) if (ready)
{ {
...@@ -161,10 +161,10 @@ namespace typon ...@@ -161,10 +161,10 @@ namespace typon
} }
} }
Future(Future && other) = default; Async(Async && other) = default;
Future& operator=(Future && other) = default; Async& operator=(Async && other) = default;
~Future() ~Async()
{ {
if (!_result) if (!_result)
{ {
...@@ -184,7 +184,7 @@ namespace typon ...@@ -184,7 +184,7 @@ namespace typon
template <typename T> template <typename T>
struct Future<T&> struct Async<T&>
{ {
using value_type = T&; using value_type = T&;
...@@ -192,7 +192,7 @@ namespace typon ...@@ -192,7 +192,7 @@ namespace typon
T * _value; T * _value;
template <typename Promise> template <typename Promise>
Future(std::coroutine_handle<Promise> coroutine, bool ready) Async(std::coroutine_handle<Promise> coroutine, bool ready)
{ {
if (ready) if (ready)
{ {
...@@ -217,14 +217,14 @@ namespace typon ...@@ -217,14 +217,14 @@ namespace typon
template <> template <>
struct Future<void> struct Async<void>
{ {
using value_type = void; using value_type = void;
Result<void> * _result = nullptr; Result<void> * _result = nullptr;
template <typename Promise> template <typename Promise>
Future(std::coroutine_handle<Promise> coroutine, bool ready) Async(std::coroutine_handle<Promise> coroutine, bool ready)
{ {
if (ready) if (ready)
{ {
...@@ -249,4 +249,4 @@ namespace typon ...@@ -249,4 +249,4 @@ namespace typon
} }
#endif // TYPON_FUTURE_HPP_INCLUDED #endif // TYPON_ASYNC_HPP_INCLUDED
...@@ -4,8 +4,8 @@ ...@@ -4,8 +4,8 @@
#include <coroutine> #include <coroutine>
#include <cstdint> #include <cstdint>
#include <typon/core/async.hpp>
#include <typon/core/continuation.hpp> #include <typon/core/continuation.hpp>
#include <typon/core/future.hpp>
#include <typon/core/result.hpp> #include <typon/core/result.hpp>
#include <typon/core/scheduler.hpp> #include <typon/core/scheduler.hpp>
...@@ -102,7 +102,7 @@ namespace typon ...@@ -102,7 +102,7 @@ namespace typon
{ {
continuation.children().insert(_coroutine); continuation.children().insert(_coroutine);
} }
return Future<T>(_coroutine, !stolen); return Async<T>(_coroutine, !stolen);
} }
}; };
......
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
#include <utility> #include <utility>
#include <typon/core/async.hpp>
#include <typon/core/fork.hpp> #include <typon/core/fork.hpp>
#include <typon/core/future.hpp>
#include <typon/core/join.hpp> #include <typon/core/join.hpp>
#include <typon/core/root.hpp> #include <typon/core/root.hpp>
#include <typon/core/task.hpp> #include <typon/core/task.hpp>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment