#pragma once
#include <memory>
namespace ableton
{
namespace util
{
template <typename Delegate>
struct SafeAsyncHandler
{
SafeAsyncHandler(const std::shared_ptr<Delegate>& pDelegate)
: mpDelegate(pDelegate)
{
}
template <typename... T>
void operator()(T&&... t) const
{
std::shared_ptr<Delegate> pDelegate = mpDelegate.lock();
if (pDelegate)
{
(*pDelegate)(std::forward<T>(t)...);
}
}
std::weak_ptr<Delegate> mpDelegate;
};
template <typename Delegate>
SafeAsyncHandler<Delegate> makeAsyncSafe(const std::shared_ptr<Delegate>& pDelegate)
{
return {pDelegate};
}
} }