Jamie Reece Wilson
8944d8bd16
[+] IAsyncTimerCallback [+] ETickType.hpp [+] EWorkPriority.hpp [+] static IThreadPool::GetSelfIOProcessor() [+] static IThreadPool::GetSelfIONetInterface() [+] static IThreadPool::GetSelfIONetWorker() [-] [Source/Async/]AsyncRunnable.hpp [*] Begin encapsulating WorkerPId_t [*] WorkerPId_t no longer take strong pointers to prevent leaks given that these identifiers are copied and kept alive everywhere
70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
/***
|
|
Copyright (C) 2021-2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
File: AuAsyncFuncRunnable.cpp
|
|
Date: 2023-12-06
|
|
Date: 2021-11-2
|
|
Author: Reece
|
|
***/
|
|
#include <Source/RuntimeInternal.hpp>
|
|
#include "IAsyncRunnable.hpp"
|
|
#include "AuAsyncFuncRunnable.hpp"
|
|
|
|
namespace Aurora::Async
|
|
{
|
|
AsyncFuncRunnable::AsyncFuncRunnable(AuFunction<void()> &&callback) :
|
|
callback(AuMove(callback))
|
|
{ }
|
|
|
|
AsyncFuncRunnable::AsyncFuncRunnable(AuFunction<void()> &&callback, AuFunction<void()> &&fail) :
|
|
callback(AuMove(callback)), fail(AuMove(fail))
|
|
{ }
|
|
|
|
AsyncFuncRunnable::AsyncFuncRunnable(const AuFunction<void()> &callback) :
|
|
callback(callback)
|
|
{ }
|
|
|
|
AsyncFuncRunnable::AsyncFuncRunnable(const AuFunction<void()> &callback, const AuFunction<void()> &fail) :
|
|
callback(callback),
|
|
fail(fail)
|
|
{ }
|
|
|
|
void AsyncFuncRunnable::RunAsync()
|
|
{
|
|
AU_LOCK_GUARD(this->lock);
|
|
|
|
try
|
|
{
|
|
if (auto callback = AuExchange(this->callback, {}))
|
|
{
|
|
callback();
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
this->CancelAsync();
|
|
}
|
|
|
|
this->fail = {};
|
|
}
|
|
|
|
void AsyncFuncRunnable::CancelAsync()
|
|
{
|
|
AU_LOCK_GUARD(this->lock);
|
|
|
|
try
|
|
{
|
|
if (auto callback = AuExchange(this->fail, {}))
|
|
{
|
|
callback();
|
|
}
|
|
}
|
|
catch (...)
|
|
{
|
|
SysPushErrorCatch();
|
|
}
|
|
|
|
this->callback = {};
|
|
}
|
|
} |