// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
#pragma once
#include "Engine/Platform/Thread.h"
#include "Threading.h"
#include "IRunnable.h"
///
/// Helper class to spawn custom thread for performing long-time action. Don't use it for short tasks.
///
class FLAXENGINE_API ThreadSpawner
{
public:
///
/// Starts a new thread the specified callback.
///
/// The callback function.
/// Name of the thread.
/// The thread priority.
/// The created thread.
static Thread* Start(const Function& callback, const String& threadName, ThreadPriority priority = ThreadPriority::Normal)
{
auto runnable = New(true);
runnable->OnWork = callback;
return Thread::Create(runnable, threadName, priority);
}
};