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