47 lines
906 B
C++
47 lines
906 B
C++
/***
|
|
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: Async.hpp
|
|
Date: 2021-6-26
|
|
Author: Reece
|
|
***/
|
|
#pragma once
|
|
|
|
namespace Aurora::Async
|
|
{
|
|
class IAsyncRunnable
|
|
{
|
|
public:
|
|
virtual void RunAsync() = 0;
|
|
|
|
virtual void CancelAsync() {}
|
|
};
|
|
|
|
class AsyncFuncRunnable : public IAsyncRunnable
|
|
{
|
|
public:
|
|
|
|
std::function<void()> callback;
|
|
|
|
AsyncFuncRunnable(std::function<void()> &&callback) : callback(std::move(callback))
|
|
{}
|
|
|
|
AsyncFuncRunnable(const std::function<void()> &callback) : callback(callback)
|
|
{}
|
|
|
|
void RunAsync() override
|
|
{
|
|
try
|
|
{
|
|
callback();
|
|
}
|
|
catch (...)
|
|
{
|
|
Debug::PrintError();
|
|
}
|
|
}
|
|
};
|
|
|
|
void InitAsync();
|
|
void ShutdownAsync();
|
|
} |