namespace LinuxCrashReporterTracker
{
	FProcHandle CurrentlyRunningCrashReporter;
	FDelegateHandle CurrentTicker;

	bool Tick(float DeltaTime)
	{
		if (!FPlatformProcess::IsProcRunning(CurrentlyRunningCrashReporter))
		{
			FPlatformProcess::CloseProc(CurrentlyRunningCrashReporter);
			CurrentlyRunningCrashReporter = FProcHandle();

			FTicker::GetCoreTicker().RemoveTicker(CurrentTicker);
			CurrentTicker.Reset();

			UE_LOG(LogLinux, Log, TEXT("Done sending crash report for ensure()."));
			return false;
		}

		// tick again
		return true;
	}

	/**
	 * Waits for the proc with timeout (busy loop, workaround for platform abstraction layer not exposing this)
	 *
	 * @param Proc proc handle to wait for
	 * @param TimeoutInSec timeout in seconds
	 * @param SleepIntervalInSec sleep interval (the smaller the more CPU we will eat, but the faster we will detect the program exiting)
	 *
	 * @return true if exited cleanly, false if timeout has expired
	 */
	bool WaitForProcWithTimeout(FProcHandle Proc, const double TimeoutInSec, const double SleepIntervalInSec)
	{
		double StartSeconds = FPlatformTime::Seconds();
		for (;;)
		{
			if (!FPlatformProcess::IsProcRunning(Proc))
			{
				break;
			}

			if (FPlatformTime::Seconds() - StartSeconds > TimeoutInSec)
			{
				return false;
			}

			FPlatformProcess::Sleep(SleepIntervalInSec);
		};

		return true;
	}
}
void UOnlineSessionClient::DestroyExistingSession_Impl(FDelegateHandle& OutResult, FName SessionName, FOnDestroySessionCompleteDelegate& Delegate)
{
	IOnlineSessionPtr SessionInt = GetSessionInt();

	if (SessionInt.IsValid())
	{
		OutResult = SessionInt->AddOnDestroySessionCompleteDelegate_Handle(Delegate);
		SessionInt->DestroySession(SessionName);
	}
	else
	{
		OutResult.Reset();
		Delegate.ExecuteIfBound(SessionName, true);
	}
}
	bool Tick(float DeltaTime)
	{
		if (!FPlatformProcess::IsProcRunning(CurrentlyRunningCrashReporter))
		{
			FPlatformProcess::CloseProc(CurrentlyRunningCrashReporter);
			CurrentlyRunningCrashReporter = FProcHandle();

			FTicker::GetCoreTicker().RemoveTicker(CurrentTicker);
			CurrentTicker.Reset();

			UE_LOG(LogLinux, Log, TEXT("Done sending crash report for ensure()."));
			return false;
		}

		// tick again
		return true;
	}