Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,30 @@

public class WaitForBackgroundThread
{
private readonly bool canFallbackToMainThread;
private readonly bool platformSupportsMultithread;

public WaitForBackgroundThread() : this(false) { }

public WaitForBackgroundThread(bool canFallbackToMainThread)
{
this.canFallbackToMainThread = canFallbackToMainThread;
this.platformSupportsMultithread = Application.platform != RuntimePlatform.WebGLPlayer;
}

public ConfiguredTaskAwaitable.ConfiguredTaskAwaiter GetAwaiter()
{
return Task.Run(() => {}).ConfigureAwait(false).GetAwaiter();
if (!platformSupportsMultithread && !canFallbackToMainThread)
{
throw new InvalidOperationException($"{Application.platform} does not support background threads.");
}

return Empty().ConfigureAwait(!platformSupportsMultithread).GetAwaiter();
}

private static async Task Empty()
{
// Task.Run does not run on WebGL, so we use this async method instead.
await Task.Yield();
}
}