2
0
Fork 0
OB-Xd/Modules/gin/utilities/threading.cpp
2020-05-21 09:14:57 +02:00

43 lines
962 B
C++
Executable file

/*==============================================================================
Copyright 2018 by Roland Rabien
For more information visit www.rabiensoftware.com
==============================================================================*/
#pragma once
//==============================================================================
class BackgroundCaller : private Thread,
private AsyncUpdater
{
public:
BackgroundCaller (std::function<void (void)> func)
: Thread ("BackgroundCaller"), function (func)
{
startThread();
}
~BackgroundCaller() override
{
stopThread (1000);
}
void run() override
{
function();
triggerAsyncUpdate();
}
void handleAsyncUpdate() override
{
delete this;
}
std::function<void (void)> function;
};
void callInBackground (std::function<void (void)> function)
{
new BackgroundCaller (function);
}