/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary> public static async UniTask <T> Run <T>(Func <object, UniTask <T> > func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await UniTask.SwitchToThreadPool(); cancellationToken.ThrowIfCancellationRequested(); if (configureAwait) { try { return(await func(state)); } finally { cancellationToken.ThrowIfCancellationRequested(); await UniTask.Yield(); cancellationToken.ThrowIfCancellationRequested(); } } else { var result = await func(state); cancellationToken.ThrowIfCancellationRequested(); return(result); } }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> public static async UniTask RunOnThreadPool(Action action, bool configureAwait = true, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await UniTask.SwitchToThreadPool(); cancellationToken.ThrowIfCancellationRequested(); if (configureAwait) { try { action(); } finally { await UniTask.Yield(); } } else { action(); } cancellationToken.ThrowIfCancellationRequested(); }
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary> public static async UniTask <T> Run <T>(Func <T> func, bool configureAwait = true, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await UniTask.SwitchToThreadPool(); cancellationToken.ThrowIfCancellationRequested(); if (configureAwait) { try { return(func()); } finally { await UniTask.Yield(); cancellationToken.ThrowIfCancellationRequested(); } } else { return(func()); } }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> public static async UniTask Run(Func <object, UniTask> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); await UniTask.SwitchToThreadPool(); cancellationToken.ThrowIfCancellationRequested(); if (configureAwait) { try { await action(state); } finally { await UniTask.Yield(); } } else { await action(state); } cancellationToken.ThrowIfCancellationRequested(); }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> public static async UniTask <T> Run <T>(Func <T> func, bool configureAwait = true) { await UniTask.SwitchToThreadPool(); if (configureAwait) { try { return(func()); } finally { await UniTask.Yield(); } } else { return(func()); } }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> public static async UniTask Run(Action action, bool configureAwait = true) { await UniTask.SwitchToThreadPool(); if (configureAwait) { try { action(); } finally { await UniTask.Yield(); } } else { action(); } }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> public static async UniTask Run(Func <object, UniTask> action, object state, bool configureAwait = true) { await UniTask.SwitchToThreadPool(); if (configureAwait) { try { await action(state); } finally { await UniTask.Yield(); } } else { await action(state); } }