Compare commits

...

32 Commits

Author SHA1 Message Date
neuecc
a2eb75df68 Merge remote-tracking branch 'origin/master' 2020-11-09 16:08:20 +09:00
neuecc
4a62d7eba6 2.0.37 2020-11-09 16:08:17 +09:00
Yoshifumi Kawai
40d2d2fe06 Merge pull request #189 from IllusionCui/master
[DoTween]:fix CancellationToken can't stop UniTask
2020-11-09 15:52:13 +09:00
neuecc
d5d2cb5937 use Dictionary instead of ConcurrentDictionary for safety of WebGL build, #179 2020-11-09 14:34:11 +09:00
neuecc
854100c075 fix invalid usage of SpinLock, #195 2020-11-09 14:20:03 +09:00
cuibeibei
5837b26208 [DoTween]:fix CancellationToken can't stop UniTask 2020-10-28 18:48:10 +08:00
Yoshifumi Kawai
da0e654e7d Merge pull request #183 from Cysharp/chore/github_Actions_security_fix
chore: replace set-env to ENV FILE $GITHUB_ENV
2020-10-14 12:39:48 +09:00
Ikiru Yoshizaki
a3e9932be7 chore: replace set-env to ENV FILE $GITHUB_ENV
fix https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
2020-10-14 12:12:28 +09:00
neuecc
e82353b4d9 UNITY_WEBGL unittest 2020-10-07 10:38:27 +09:00
Yoshifumi Kawai
944b61f28c Update README.md 2020-09-25 17:32:17 +09:00
Yoshifumi Kawai
457c574865 Update README.md 2020-09-24 10:31:59 +09:00
Yoshifumi Kawai
089a509663 Update README.md 2020-09-23 17:16:09 +09:00
neuecc
3bebaef969 2.0.36 2020-09-22 10:49:04 +09:00
neuecc
37e8b4500e Add enumerator.ToUniTask(MonoBehaviour coroutineRunner), log WARN on await enumerator when yield not supported types(Coroutine, WaitForEndOfFrame, WaitForFixedUpdate). 2020-09-22 10:08:03 +09:00
neuecc
8537ddf8a6 fix Forget when source is already completed and source is manualy optimized task source, does not work correctly 2020-09-22 09:54:05 +09:00
neuecc
346b1e0a6b 2.0.35 2020-09-21 12:56:13 +09:00
neuecc
fc7b9660a5 remove OnMouse_event trigger to prevent warning on Andoird, iOS, #170 2020-09-21 12:50:25 +09:00
neuecc
21e5cc22c7 notice for WaitForEndOfFrame #169 2020-09-21 12:49:26 +09:00
neuecc
3f18b37e5f changed clear loop runner queue timing in UnityEditor and run rest action when quitted 2020-09-21 12:30:31 +09:00
neuecc
5d4a90e9bd fix broken loop-runner from 2.0.32, #172 2020-09-21 11:42:02 +09:00
neuecc
2bf9f4f062 fix 2020-09-16 09:58:30 +09:00
neuecc
d69490cb49 one more things 2020-09-16 09:55:14 +09:00
neuecc
4e460c11ca 2.0.34 2020-09-16 09:48:57 +09:00
neuecc
9313969314 2.0.33 2020-09-15 06:53:58 +09:00
neuecc
a40f89a922 Merge remote-tracking branch 'origin/master' 2020-09-15 06:35:28 +09:00
neuecc
e0d8410b62 fix IEnumerator.ToUniTask, does not work correctly when coroutine complete immediately 2020-09-15 06:35:22 +09:00
Yoshifumi Kawai
bef1bd8ad1 Merge pull request #164 from c0nd3v/master
Fixed AwaitForAllAssets()
2020-09-12 06:09:29 +09:00
c0nd3v
81b4fcfac1 Fixed AwaitForAllAssets() 2020-09-11 10:41:41 -04:00
Yoshifumi Kawai
f1e4a3c65d Merge pull request #162 from hikarin522/patch-3
Fix UniTaskExtensions.Unwrap()
2020-09-09 15:38:03 +09:00
hikari
65622b01f6 [Unwrap] add ConfigureAwait 2020-09-09 14:15:03 +09:00
hikari
87dd5f13fd [Unwrap()] fix: remove type parameter 2020-09-09 14:05:37 +09:00
Yoshifumi Kawai
79cd2c17ba Update README.md 2020-09-07 18:55:44 +09:00
24 changed files with 360 additions and 121 deletions

View File

@@ -3,7 +3,7 @@ name: Build-Debug
on: on:
push: push:
branches: branches:
- "**" - "master"
tags: tags:
- "!*" # not a tag push - "!*" # not a tag push
pull_request: pull_request:
@@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1 - uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 3.1.101 dotnet-version: 3.1.x
- run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj - run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj
build-unity: build-unity:

View File

@@ -16,9 +16,9 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/setup-dotnet@v1 - uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 3.1.101 dotnet-version: 3.1.x
# set release tag(*.*.*) to env.GIT_TAG # set release tag(*.*.*) to env.GIT_TAG
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/} - run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# build and pack # build and pack
- run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }} - run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }}
@@ -34,7 +34,7 @@ jobs:
build-unity: build-unity:
strategy: strategy:
matrix: matrix:
unity: ['2019.3.9f1'] unity: ["2019.3.9f1"]
include: include:
- unity: 2019.3.9f1 - unity: 2019.3.9f1
license: UNITY_2019_3 license: UNITY_2019_3
@@ -51,7 +51,7 @@ jobs:
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0 - run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0
# set release tag(*.*.*) to env.GIT_TAG # set release tag(*.*.*) to env.GIT_TAG
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/} - run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# Execute scripts: Export Package # Execute scripts: Export Package
- name: Export unitypackage - name: Export unitypackage
@@ -72,34 +72,34 @@ jobs:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1 DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
NUGET_XMLDOC_MODE: skip NUGET_XMLDOC_MODE: skip
steps: steps:
# setup dotnet for nuget push # setup dotnet for nuget push
- uses: actions/setup-dotnet@v1 - uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 3.1.101 dotnet-version: 3.1.x
# set release tag(*.*.*) to env.GIT_TAG # set release tag(*.*.*) to env.GIT_TAG
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/} - run: echo "GIT_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
# Create Releases # Create Releases
- uses: actions/create-release@v1 - uses: actions/create-release@v1
id: create_release id: create_release
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
tag_name: ${{ github.ref }} tag_name: ${{ github.ref }}
release_name: Ver.${{ github.ref }} release_name: Ver.${{ github.ref }}
# Download(All) Artifacts to current directory # Download(All) Artifacts to current directory
- uses: actions/download-artifact@v2-preview - uses: actions/download-artifact@v2-preview
# Upload to NuGet # Upload to NuGet
- run: dotnet nuget push "./nuget/*.nupkg" -s https://www.nuget.org/api/v2/package -k ${{ secrets.NUGET_KEY }} - run: dotnet nuget push "./nuget/*.nupkg" -s https://www.nuget.org/api/v2/package -k ${{ secrets.NUGET_KEY }}
# Upload to Releases(unitypackage) # Upload to Releases(unitypackage)
- uses: actions/upload-release-asset@v1 - uses: actions/upload-release-asset@v1
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with: with:
upload_url: ${{ steps.create_release.outputs.upload_url }} upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./UniTask.${{ env.GIT_TAG }}.unitypackage/UniTask.${{ env.GIT_TAG }}.unitypackage asset_path: ./UniTask.${{ env.GIT_TAG }}.unitypackage/UniTask.${{ env.GIT_TAG }}.unitypackage
asset_name: UniTask.${{ env.GIT_TAG }}.unitypackage asset_name: UniTask.${{ env.GIT_TAG }}.unitypackage
asset_content_type: application/octet-stream asset_content_type: application/octet-stream

View File

@@ -15,6 +15,7 @@ Provides an efficient allocation free async/await integration to Unity.
Techinical details, see blog post: [UniTask v2 — Zero Allocation async/await for Unity, with Asynchronous LINQ Techinical details, see blog post: [UniTask v2 — Zero Allocation async/await for Unity, with Asynchronous LINQ
](https://medium.com/@neuecc/unitask-v2-zero-allocation-async-await-for-unity-with-asynchronous-linq-1aa9c96aa7dd) ](https://medium.com/@neuecc/unitask-v2-zero-allocation-async-await-for-unity-with-asynchronous-linq-1aa9c96aa7dd)
Advanced tips, see blog post: [Extends UnityWebRequest via async decorator pattern — Advanced Techniques of UniTask](https://medium.com/@neuecc/extends-unitywebrequest-via-async-decorator-pattern-advanced-techniques-of-unitask-ceff9c5ee846)
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
@@ -214,6 +215,8 @@ await task; // NG, throws Exception
Store to the class field, you can use `UniTask.Lazy` that gurantee call multipletimes. `.Preserve()` allows for multiple calls (internally cached results). This is useful when multiple calls in a function scope. Store to the class field, you can use `UniTask.Lazy` that gurantee call multipletimes. `.Preserve()` allows for multiple calls (internally cached results). This is useful when multiple calls in a function scope.
Also `UniTaskCompletionSource` can await multipletimes and await from many caller.
Cancellation and Exception handling Cancellation and Exception handling
--- ---
Some UniTask factory methods have `CancellationToken cancellationToken = default` parameter. Andalso some async operation for unity have `WithCancellation(CancellationToken)` and `ToUniTask(..., CancellationToken cancellation = default)` extension methods. Some UniTask factory methods have `CancellationToken cancellationToken = default` parameter. Andalso some async operation for unity have `WithCancellation(CancellationToken)` and `ToUniTask(..., CancellationToken cancellation = default)` extension methods.
@@ -350,6 +353,8 @@ It indicates when to run, you can check [PlayerLoopList.md](https://gist.github.
`PlayerLoopTiming.Update` is similar as `yield return null` in coroutine, but it is called before Update(Update and uGUI events(button.onClick, etc...) are called on `ScriptRunBehaviourUpdate`, yield return null is called on `ScriptRunDelayedDynamicFrameRate`). `PlayerLoopTiming.FixedUpdate` is similar as `WaitForFixedUpdate`, `PlayerLoopTiming.LastPostLateUpdate` is similar as `WaitForEndOfFrame` in coroutine. `PlayerLoopTiming.Update` is similar as `yield return null` in coroutine, but it is called before Update(Update and uGUI events(button.onClick, etc...) are called on `ScriptRunBehaviourUpdate`, yield return null is called on `ScriptRunDelayedDynamicFrameRate`). `PlayerLoopTiming.FixedUpdate` is similar as `WaitForFixedUpdate`, `PlayerLoopTiming.LastPostLateUpdate` is similar as `WaitForEndOfFrame` in coroutine.
> `await UniTask.WaitForEndOfFrame()` is not equilavelnt to coroutine's `yield return new WaitForEndOfFrame()`. Coroutine's WaitForEndOfFrame seems to run after the PlayerLoop is done. Some methods that require coroutine's end of frame(`ScreenCapture.CaptureScreenshotAsTexture`, `CommandBuffer`, etc) does not work correctly when replace to async/await. In that case, use a coroutine.
`yield return null` and `UniTask.Yield` is similar but different. `yield return null` always return next frame but `UniTask.Yield` return next called, that is, call `UniTask.Yield(PlayerLoopTiming.Update)` on `PreUpdate`, it returns same frame. `UniTask.NextFrame()` gurantees return next frame, this would be expected to behave exactly the same as `yield return null`. `yield return null` and `UniTask.Yield` is similar but different. `yield return null` always return next frame but `UniTask.Yield` return next called, that is, call `UniTask.Yield(PlayerLoopTiming.Update)` on `PreUpdate`, it returns same frame. `UniTask.NextFrame()` gurantees return next frame, this would be expected to behave exactly the same as `yield return null`.
> UniTask.Yield(without CancellationToken) is a special type, returns `YieldAwaitable` and run on YieldRunner. It is most lightweight and faster. > UniTask.Yield(without CancellationToken) is a special type, returns `YieldAwaitable` and run on YieldRunner. It is most lightweight and faster.
@@ -793,9 +798,11 @@ IEnumerator.ToUniTask limitation
--- ---
You can convert coroutine(IEnumerator) to UniTask(or await directly) but has some limitations. You can convert coroutine(IEnumerator) to UniTask(or await directly) but has some limitations.
* `WaitForEndOfFrame`/`WaitForFixedUpdate` is not supported, used `yield return null` instead. * `WaitForEndOfFrame`/`WaitForFixedUpdate`/`Coroutine` is not supported.
* Consuming loop timing is not same as StartCoroutine, it is used specified PlayerLoopTiming, and default's `PlayerLoopTiming.Update` is run before MonoBehaviour's Update and StartCoroutine's loop. * Consuming loop timing is not same as StartCoroutine, it is used specified PlayerLoopTiming, and default's `PlayerLoopTiming.Update` is run before MonoBehaviour's Update and StartCoroutine's loop.
If you want to convert fully compatible from coroutine to async, use `IEnumerator.ToUniTask(MonoBehaviour coroutineRunner)` overload. It executes StartCoroutine on an instance of the argument MonoBehaviour and waits for it to complete in UniTask.
For UnityEditor For UnityEditor
--- ---
UniTask can run on Unity Edtitor like Editor Coroutine. However, there are some limitations. UniTask can run on Unity Edtitor like Editor Coroutine. However, there are some limitations.
@@ -851,7 +858,7 @@ Use UniTask type.
Pooling Configuration Pooling Configuration
--- ---
UniTask is aggressively caching async promise object to achive zero allocation. In default, cache all promises but you can configure `TaskPool.SetMaxPoolSize` to your value, the value indicates cache size per type. `TaskPool.GetCacheSizeInfo` returns current cached object in pool. UniTask is aggressively caching async promise object to achive zero allocation(technical details, see blog post [UniTask v2 — Zero Allocation async/await for Unity, with Asynchronous LINQ](https://medium.com/@neuecc/unitask-v2-zero-allocation-async-await-for-unity-with-asynchronous-linq-1aa9c96aa7dd)). In default, cache all promises but you can configure `TaskPool.SetMaxPoolSize` to your value, the value indicates cache size per type. `TaskPool.GetCacheSizeInfo` returns current cached object in pool.
```csharp ```csharp
foreach (var (type, size) in TaskPool.GetCacheSizeInfo()) foreach (var (type, size) in TaskPool.GetCacheSizeInfo())
@@ -905,7 +912,7 @@ After Unity 2019.3.4f1, Unity 2020.1a21, that support path query parameter of gi
or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`. or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask"` to `Packages/manifest.json`.
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.31`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.31`. If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.36`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.36`.
### Install via OpenUPM ### Install via OpenUPM

View File

@@ -32,6 +32,19 @@ namespace Cysharp.Threading.Tasks
return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token); return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token);
} }
public static UniTask ToUniTask(this IEnumerator enumerator, MonoBehaviour coroutineRunner)
{
var source = AutoResetUniTaskCompletionSource.Create();
coroutineRunner.StartCoroutine(Core(enumerator, coroutineRunner, source));
return source.Task;
}
static IEnumerator Core(IEnumerator inner, MonoBehaviour coroutineRunner, AutoResetUniTaskCompletionSource source)
{
yield return coroutineRunner.StartCoroutine(inner);
source.TrySetResult();
}
sealed class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<EnumeratorPromise> sealed class EnumeratorPromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<EnumeratorPromise>
{ {
static TaskPool<EnumeratorPromise> pool; static TaskPool<EnumeratorPromise> pool;
@@ -46,6 +59,8 @@ namespace Cysharp.Threading.Tasks
IEnumerator innerEnumerator; IEnumerator innerEnumerator;
CancellationToken cancellationToken; CancellationToken cancellationToken;
int initialFrame; int initialFrame;
bool loopRunning;
bool calledGetResult;
UniTaskCompletionSourceCore<object> core; UniTaskCompletionSourceCore<object> core;
@@ -68,6 +83,8 @@ namespace Cysharp.Threading.Tasks
result.innerEnumerator = ConsumeEnumerator(innerEnumerator); result.innerEnumerator = ConsumeEnumerator(innerEnumerator);
result.cancellationToken = cancellationToken; result.cancellationToken = cancellationToken;
result.loopRunning = true;
result.calledGetResult = false;
result.initialFrame = -1; result.initialFrame = -1;
PlayerLoopHelper.AddAction(timing, result); PlayerLoopHelper.AddAction(timing, result);
@@ -82,11 +99,15 @@ namespace Cysharp.Threading.Tasks
{ {
try try
{ {
calledGetResult = true;
core.GetResult(token); core.GetResult(token);
} }
finally finally
{ {
TryReturn(); if (!loopRunning)
{
TryReturn();
}
} }
} }
@@ -107,8 +128,21 @@ namespace Cysharp.Threading.Tasks
public bool MoveNext() public bool MoveNext()
{ {
if (calledGetResult)
{
loopRunning = false;
TryReturn();
return false;
}
if (innerEnumerator == null) // invalid status, returned but loop running?
{
return false;
}
if (cancellationToken.IsCancellationRequested) if (cancellationToken.IsCancellationRequested)
{ {
loopRunning = false;
core.TrySetCanceled(cancellationToken); core.TrySetCanceled(cancellationToken);
return false; return false;
} }
@@ -135,10 +169,12 @@ namespace Cysharp.Threading.Tasks
} }
catch (Exception ex) catch (Exception ex)
{ {
loopRunning = false;
core.TrySetException(ex); core.TrySetException(ex);
return false; return false;
} }
loopRunning = false;
core.TrySetResult(null); core.TrySetResult(null);
return false; return false;
} }
@@ -192,7 +228,7 @@ namespace Cysharp.Threading.Tasks
} }
else else
{ {
yield return null; goto WARN;
} }
} }
else if (current is IEnumerator e3) else if (current is IEnumerator e3)
@@ -205,9 +241,15 @@ namespace Cysharp.Threading.Tasks
} }
else else
{ {
// WaitForEndOfFrame, WaitForFixedUpdate, others. goto WARN;
yield return null;
} }
continue;
WARN:
// WaitForEndOfFrame, WaitForFixedUpdate, others.
UnityEngine.Debug.LogWarning($"yield {current.GetType().Name} is not supported on await IEnumerator or IEnumerator.ToUniTask(), please use ToUniTask(MonoBehaviour coroutineRunner) instead.");
yield return null;
} }
} }
@@ -239,4 +281,3 @@ namespace Cysharp.Threading.Tasks
} }
} }
} }

View File

@@ -31,7 +31,8 @@ namespace Cysharp.Threading.Tasks
if (!handle.IsValid()) if (!handle.IsValid())
{ {
throw new Exception("Attempting to use an invalid operation handle"); // autoReleaseHandle:true handle is invalid(immediately internal handle == null) so return completed.
return UniTask.CompletedTask;
} }
if (handle.IsDone) if (handle.IsDone)

View File

@@ -223,6 +223,17 @@ namespace Cysharp.Threading.Tasks
void OnCompleteCallbackDelegate() void OnCompleteCallbackDelegate()
{ {
if (cancellationToken.IsCancellationRequested)
{
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
{
canceled = true;
}
}
if (canceled) if (canceled)
{ {
core.TrySetCanceled(cancellationToken); core.TrySetCanceled(cancellationToken);

View File

@@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.Internal
readonly PlayerLoopTiming timing; readonly PlayerLoopTiming timing;
SpinLock gate = new SpinLock(); SpinLock gate = new SpinLock(false);
bool dequing = false; bool dequing = false;
int actionListCount = 0; int actionListCount = 0;
@@ -70,13 +70,17 @@ namespace Cysharp.Threading.Tasks.Internal
} }
} }
public void Clear() public int Clear()
{ {
var rest = actionListCount + waitingListCount;
actionListCount = 0; actionListCount = 0;
actionList = new Action[InitialSize]; actionList = new Action[InitialSize];
waitingListCount = 0; waitingListCount = 0;
waitingList = new Action[InitialSize]; waitingList = new Action[InitialSize];
return rest;
} }
// delegate entrypoint. // delegate entrypoint.

View File

@@ -48,14 +48,24 @@ namespace Cysharp.Threading.Tasks.Internal
} }
} }
public void Clear() public int Clear()
{ {
lock (arrayLock) lock (arrayLock)
{ {
var rest = 0;
for (var index = 0; index < loopItems.Length; index++) for (var index = 0; index < loopItems.Length; index++)
{ {
if (loopItems[index] != null)
{
rest++;
}
loopItems[index] = null; loopItems[index] = null;
} }
tail = 0;
return rest;
} }
} }
@@ -143,8 +153,6 @@ namespace Cysharp.Threading.Tasks.Internal
{ {
var j = tail - 1; var j = tail - 1;
var loopItems = this.loopItems;
// eliminate array-bound check for i
for (int i = 0; i < loopItems.Length; i++) for (int i = 0; i < loopItems.Length; i++)
{ {
var action = loopItems[i]; var action = loopItems[i];

View File

@@ -110,27 +110,30 @@ namespace Cysharp.Threading.Tasks
#if UNITY_EDITOR #if UNITY_EDITOR
EditorApplication.playModeStateChanged += (state) => EditorApplication.playModeStateChanged += (state) =>
{ {
if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.EnteredPlayMode) if (state == PlayModeStateChange.EnteredEditMode || state == PlayModeStateChange.ExitingEditMode)
{ {
return; // run rest action before clear.
} if (runner != null)
{
runner.Run();
runner.Clear();
}
if (lastRunner != null)
{
lastRunner.Run();
lastRunner.Clear();
}
if (runner != null) if (cq != null)
{ {
runner.Clear(); cq.Run();
} cq.Clear();
if (lastRunner != null) }
{ if (lastCq != null)
lastRunner.Clear(); {
} lastCq.Run();
lastCq.Clear();
if (cq != null) }
{
cq.Clear();
}
if (lastCq != null)
{
lastCq.Clear();
} }
}; };
#endif #endif

View File

@@ -12,7 +12,9 @@ namespace Cysharp.Threading.Tasks
public static class TaskPool public static class TaskPool
{ {
internal static int MaxPoolSize; internal static int MaxPoolSize;
static ConcurrentDictionary<Type, Func<int>> sizes = new ConcurrentDictionary<Type, Func<int>>();
// avoid to use ConcurrentDictionary for safety of WebGL build.
static Dictionary<Type, Func<int>> sizes = new Dictionary<Type, Func<int>>();
static TaskPool() static TaskPool()
{ {
@@ -40,19 +42,24 @@ namespace Cysharp.Threading.Tasks
public static IEnumerable<(Type, int)> GetCacheSizeInfo() public static IEnumerable<(Type, int)> GetCacheSizeInfo()
{ {
foreach (var item in sizes) lock (sizes)
{ {
yield return (item.Key, item.Value()); foreach (var item in sizes)
{
yield return (item.Key, item.Value());
}
} }
} }
public static void RegisterSizeGetter(Type type, Func<int> getSize) public static void RegisterSizeGetter(Type type, Func<int> getSize)
{ {
sizes[type] = getSize; lock (sizes)
{
sizes[type] = getSize;
}
} }
} }
public interface ITaskPoolNode<T> public interface ITaskPoolNode<T>
{ {
ref T NextNode { get; } ref T NextNode { get; }

View File

@@ -1541,6 +1541,7 @@ namespace Cysharp.Threading.Tasks.Triggers
#endregion #endregion
#region MouseDown #region MouseDown
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseDownHandler public interface IAsyncOnMouseDownHandler
{ {
@@ -1597,9 +1598,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDownAsync(); return ((IAsyncOnMouseDownHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDownAsync();
} }
} }
#endif
#endregion #endregion
#region MouseDrag #region MouseDrag
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseDragHandler public interface IAsyncOnMouseDragHandler
{ {
@@ -1656,9 +1659,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDragAsync(); return ((IAsyncOnMouseDragHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseDragAsync();
} }
} }
#endif
#endregion #endregion
#region MouseEnter #region MouseEnter
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseEnterHandler public interface IAsyncOnMouseEnterHandler
{ {
@@ -1715,9 +1720,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseEnterAsync(); return ((IAsyncOnMouseEnterHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseEnterAsync();
} }
} }
#endif
#endregion #endregion
#region MouseExit #region MouseExit
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseExitHandler public interface IAsyncOnMouseExitHandler
{ {
@@ -1774,9 +1781,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseExitAsync(); return ((IAsyncOnMouseExitHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseExitAsync();
} }
} }
#endif
#endregion #endregion
#region MouseOver #region MouseOver
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseOverHandler public interface IAsyncOnMouseOverHandler
{ {
@@ -1833,9 +1842,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseOverAsync(); return ((IAsyncOnMouseOverHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseOverAsync();
} }
} }
#endif
#endregion #endregion
#region MouseUp #region MouseUp
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseUpHandler public interface IAsyncOnMouseUpHandler
{ {
@@ -1892,9 +1903,11 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsync(); return ((IAsyncOnMouseUpHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsync();
} }
} }
#endif
#endregion #endregion
#region MouseUpAsButton #region MouseUpAsButton
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
public interface IAsyncOnMouseUpAsButtonHandler public interface IAsyncOnMouseUpAsButtonHandler
{ {
@@ -1951,6 +1964,7 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsButtonAsync(); return ((IAsyncOnMouseUpAsButtonHandler)new AsyncTriggerHandler<AsyncUnit>(this, cancellationToken, true)).OnMouseUpAsButtonAsync();
} }
} }
#endif
#endregion #endregion
#region ParticleCollision #region ParticleCollision

View File

@@ -25,13 +25,7 @@
("Update", "Update", "AsyncUnit", null, empty), ("Update", "Update", "AsyncUnit", null, empty),
("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty), ("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty),
("LateUpdate", "LateUpdate", "AsyncUnit", null, empty), ("LateUpdate", "LateUpdate", "AsyncUnit", null, empty),
("MouseDown", "OnMouseDown", "AsyncUnit", null, empty),
("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty),
("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty),
("MouseExit", "OnMouseExit", "AsyncUnit", null, empty),
("MouseOver", "OnMouseOver", "AsyncUnit", null, empty),
("MouseUp", "OnMouseUp", "AsyncUnit", null, empty),
("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty),
("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }), ("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }),
("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty), ("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty),
("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty), ("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty),
@@ -47,6 +41,15 @@
("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty), ("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty),
("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty), ("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty),
// Mouse... #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
("MouseDown", "OnMouseDown", "AsyncUnit", null, empty),
("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty),
("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty),
("MouseExit", "OnMouseExit", "AsyncUnit", null, empty),
("MouseOver", "OnMouseOver", "AsyncUnit", null, empty),
("MouseUp", "OnMouseUp", "AsyncUnit", null, empty),
("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty),
// new in v2 // new in v2
("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }), ("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }),
("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }), ("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }),
@@ -104,6 +107,7 @@
Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")"; Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")";
Func<string, bool> Is2019_3 = x => x == "ParticleUpdateJobScheduled"; Func<string, bool> Is2019_3 = x => x == "ParticleUpdateJobScheduled";
Func<string, bool> IsMouseTrigger = x => x.StartsWith("Mouse");
#> #>
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
@@ -117,6 +121,9 @@ namespace Cysharp.Threading.Tasks.Triggers
#region <#= t.triggerName #> #region <#= t.triggerName #>
<# if(Is2019_3(t.triggerName)) { #> <# if(Is2019_3(t.triggerName)) { #>
#if UNITY_2019_3_OR_NEWER #if UNITY_2019_3_OR_NEWER
<# } #>
<# if(IsMouseTrigger(t.triggerName)) { #>
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
<# } #> <# } #>
public interface <#= ToInterfaceName(t.methodName) #> public interface <#= ToInterfaceName(t.methodName) #>
@@ -174,7 +181,7 @@ namespace Cysharp.Threading.Tasks.Triggers
return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, true)).<#= t.methodName #>Async(); return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, true)).<#= t.methodName #>Async();
} }
} }
<# if(Is2019_3(t.triggerName)) { #> <# if(Is2019_3(t.triggerName) || IsMouseTrigger(t.triggerName)) { #>
#endif #endif
<# } #> <# } #>
#endregion #endregion

View File

@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks
// Run is a confusing name, use only RunOnThreadPool in the future. // Run is a confusing name, use only RunOnThreadPool in the future.
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
public static async UniTask Run(Action action, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask Run(Action action, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -39,7 +39,7 @@ namespace Cysharp.Threading.Tasks
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
public static async UniTask Run(Action<object> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask Run(Action<object> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -67,7 +67,7 @@ namespace Cysharp.Threading.Tasks
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
public static async UniTask Run(Func<UniTask> action, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask Run(Func<UniTask> action, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -95,7 +95,7 @@ namespace Cysharp.Threading.Tasks
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
public static async UniTask Run(Func<object, UniTask> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask Run(Func<object, UniTask> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -123,7 +123,7 @@ namespace Cysharp.Threading.Tasks
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <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) public static async UniTask<T> Run<T>(Func<T> func, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -150,7 +150,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
public static async UniTask<T> Run<T>(Func<UniTask<T>> func, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask<T> Run<T>(Func<UniTask<T>> func, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -180,7 +180,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <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, T> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default) public static async UniTask<T> Run<T>(Func<object, T> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
@@ -207,7 +207,7 @@ namespace Cysharp.Threading.Tasks
} }
} }
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary> /// <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) public static async UniTask<T> Run<T>(Func<object, UniTask<T>> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();

View File

@@ -561,21 +561,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex); UniTaskScheduler.PublishUnobservedTaskException(ex);
} }
} }
else
awaiter.SourceOnCompleted(state =>
{ {
using (var t = (StateTuple<UniTask.Awaiter>)state) awaiter.SourceOnCompleted(state =>
{ {
try using (var t = (StateTuple<UniTask.Awaiter>)state)
{ {
t.Item1.GetResult(); try
{
t.Item1.GetResult();
}
catch (Exception ex)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
} }
catch (Exception ex) }, StateTuple.Create(awaiter));
{ }
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
} }
public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true) public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
@@ -629,21 +631,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex); UniTaskScheduler.PublishUnobservedTaskException(ex);
} }
} }
else
awaiter.SourceOnCompleted(state =>
{ {
using (var t = (StateTuple<UniTask<T>.Awaiter>)state) awaiter.SourceOnCompleted(state =>
{ {
try using (var t = (StateTuple<UniTask<T>.Awaiter>)state)
{ {
t.Item1.GetResult(); try
{
t.Item1.GetResult();
}
catch (Exception ex)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
} }
catch (Exception ex) }, StateTuple.Create(awaiter));
{ }
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
} }
public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true) public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
@@ -732,7 +736,7 @@ namespace Cysharp.Threading.Tasks
return await await task; return await await task;
} }
public static async UniTask Unwrap<T>(this UniTask<UniTask> task) public static async UniTask Unwrap(this UniTask<UniTask> task)
{ {
await await task; await await task;
} }
@@ -742,21 +746,41 @@ namespace Cysharp.Threading.Tasks
return await await task; return await await task;
} }
public static async UniTask Unwrap<T>(this Task<UniTask> task) public static async UniTask<T> Unwrap<T>(this Task<UniTask<T>> task, bool continueOnCapturedContext)
{
return await await task.ConfigureAwait(continueOnCapturedContext);
}
public static async UniTask Unwrap(this Task<UniTask> task)
{ {
await await task; await await task;
} }
public static async UniTask Unwrap(this Task<UniTask> task, bool continueOnCapturedContext)
{
await await task.ConfigureAwait(continueOnCapturedContext);
}
public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task) public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task)
{ {
return await await task; return await await task;
} }
public static async UniTask Unwrap<T>(this UniTask<Task> task) public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task, bool continueOnCapturedContext)
{
return await (await task).ConfigureAwait(continueOnCapturedContext);
}
public static async UniTask Unwrap(this UniTask<Task> task)
{ {
await await task; await await task;
} }
public static async UniTask Unwrap(this UniTask<Task> task, bool continueOnCapturedContext)
{
await (await task).ConfigureAwait(continueOnCapturedContext);
}
#if UNITY_2018_3_OR_NEWER #if UNITY_2018_3_OR_NEWER
sealed class ToCoroutineEnumerator : IEnumerator sealed class ToCoroutineEnumerator : IEnumerator

View File

@@ -9,7 +9,7 @@ namespace Cysharp.Threading.Tasks
const int MaxArrayLength = 0X7FEFFFFF; const int MaxArrayLength = 0X7FEFFFFF;
const int InitialSize = 16; const int InitialSize = 16;
static SpinLock gate = new SpinLock(); static SpinLock gate = new SpinLock(false);
static bool dequing = false; static bool dequing = false;
static int actionListCount = 0; static int actionListCount = 0;

View File

@@ -46,6 +46,11 @@ namespace Cysharp.Threading.Tasks
this.continuationAction = null; this.continuationAction = null;
} }
public AssetBundleRequestAllAssetsAwaiter GetAwaiter()
{
return this;
}
public bool IsCompleted => asyncOperation.isDone; public bool IsCompleted => asyncOperation.isDone;
public UnityEngine.Object[] GetResult() public UnityEngine.Object[] GetResult()

View File

@@ -1,7 +1,7 @@
{ {
"name": "com.cysharp.unitask", "name": "com.cysharp.unitask",
"displayName": "UniTask", "displayName": "UniTask",
"version": "2.0.32", "version": "2.0.37",
"unity": "2018.4", "unity": "2018.4",
"description": "Provides an efficient async/await integration to Unity.", "description": "Provides an efficient async/await integration to Unity.",
"keywords": [ "async/await", "async", "Task", "UniTask" ], "keywords": [ "async/await", "async", "Task", "UniTask" ],

View File

@@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
// using UnityEngine.AddressableAssets;
/*UNniTastWhenAnyTester*/ /*UNniTastWhenAnyTester*/
@@ -49,4 +50,9 @@ public class ExceptionExamples : MonoBehaviour
await UniTask.Delay(100); await UniTask.Delay(100);
return taskIndex; return taskIndex;
} }
//void AddressablesTest()
//{
// Addressables.ClearDependencyCacheAsync("key", true);
//}
} }

View File

@@ -493,8 +493,43 @@ public class SandboxMain : MonoBehaviour
} }
async UniTask QuitCheck()
{
try
{
await UniTask.Delay(TimeSpan.FromMinutes(1), cancellationToken: quitSource.Token);
}
finally
{
Debug.Log("End QuitCheck async");
}
}
CancellationTokenSource quitSource = new CancellationTokenSource();
IEnumerator TestCor()
{
Debug.Log("start cor");
yield return null;
yield return new WaitForEndOfFrame();
Debug.Log("end cor");
}
async UniTaskVoid Start() async UniTaskVoid Start()
{ {
await TestCor().ToUniTask(this);
Debug.Log("App Start");
Application.quitting += () =>
{
Debug.Log("called quitting");
quitSource.Cancel();
};
QuitCheck().Forget();
//Expression.Lambda<Func<int>>(null).Compile(true); //Expression.Lambda<Func<int>>(null).Compile(true);
//RunStandardTaskAsync(); //RunStandardTaskAsync();

View File

@@ -55,6 +55,8 @@ namespace Cysharp.Threading.TasksTests
} }
} }
#if !UNITY_WEBGL
[UnityTest] [UnityTest]
public IEnumerator DelayAnd() => UniTask.ToCoroutine(async () => public IEnumerator DelayAnd() => UniTask.ToCoroutine(async () =>
{ {
@@ -76,6 +78,8 @@ namespace Cysharp.Threading.TasksTests
} }
}); });
#endif
[UnityTest] [UnityTest]
public IEnumerator DelayIgnore() => UniTask.ToCoroutine(async () => public IEnumerator DelayIgnore() => UniTask.ToCoroutine(async () =>
{ {
@@ -183,6 +187,8 @@ namespace Cysharp.Threading.TasksTests
diff.Should().Be(11); diff.Should().Be(11);
}); });
#if !UNITY_WEBGL
[UnityTest] [UnityTest]
public IEnumerator SwitchTo() => UniTask.ToCoroutine(async () => public IEnumerator SwitchTo() => UniTask.ToCoroutine(async () =>
{ {
@@ -215,6 +221,8 @@ namespace Cysharp.Threading.TasksTests
currentThreadId.Should().Be(switchedThreadId2); currentThreadId.Should().Be(switchedThreadId2);
}); });
#endif
//[UnityTest] //[UnityTest]
//public IEnumerator ObservableConversion() => UniTask.ToCoroutine(async () => //public IEnumerator ObservableConversion() => UniTask.ToCoroutine(async () =>
//{ //{

View File

@@ -96,6 +96,47 @@ namespace Cysharp.Threading.TasksTests
// l[1].Item2.Should().NotBe(currentFrame); // l[1].Item2.Should().NotBe(currentFrame);
//} //}
[UnityTest]
public IEnumerator ImmediateRunTest() => UniTask.ToCoroutine(async () =>
{
var l = new List<int>();
var x1 = Immediate(l);
var x2 = Immediate(l);
var x3 = DelayOne(l);
var t1 = x1.ToUniTask();
CollectionAssert.AreEqual(l, new[] { 1, 2, 3 });
await t1;
var t2 = x2.ToUniTask();
CollectionAssert.AreEqual(l, new[] { 1, 2, 3, 1, 2, 3 });
var t3 = x3.ToUniTask();
CollectionAssert.AreEqual(l, new[] { 1, 2, 3, 1, 2, 3, 10 });
await UniTask.WhenAll(t2, t3);
CollectionAssert.AreEqual(l, new[] { 1, 2, 3, 1, 2, 3, 10, 20, 30 });
});
IEnumerator Immediate(List<int> l)
{
l.Add(1);
l.Add(2);
l.Add(3);
yield break;
}
IEnumerator DelayOne(List<int> l)
{
l.Add(10);
yield return null;
l.Add(20);
l.Add(30);
}
#if !UNITY_WEBGL
[UnityTest] [UnityTest]
public IEnumerator WaitForSecondsTest() => UniTask.ToCoroutine(async () => public IEnumerator WaitForSecondsTest() => UniTask.ToCoroutine(async () =>
{ {
@@ -123,6 +164,8 @@ namespace Cysharp.Threading.TasksTests
yield return new WaitForSeconds(3.0f); yield return new WaitForSeconds(3.0f);
} }
#endif
IEnumerator Worker(List<(int, int)> l) IEnumerator Worker(List<(int, int)> l)
{ {
l.Add((0, Time.frameCount)); l.Add((0, Time.frameCount));

View File

@@ -175,6 +175,7 @@ namespace Cysharp.Threading.TasksTests
} }
}); });
#if !UNITY_WEBGL
[UnityTest] [UnityTest]
public IEnumerator DelayInThreadPool() => UniTask.ToCoroutine(async () => public IEnumerator DelayInThreadPool() => UniTask.ToCoroutine(async () =>
@@ -185,6 +186,8 @@ namespace Cysharp.Threading.TasksTests
}); });
}); });
#endif
[UnityTest] [UnityTest]
public IEnumerator DelayRealtime() => UniTask.ToCoroutine(async () => public IEnumerator DelayRealtime() => UniTask.ToCoroutine(async () =>
{ {
@@ -200,5 +203,16 @@ namespace Cysharp.Threading.TasksTests
okay1.Should().Be(true); okay1.Should().Be(true);
okay2.Should().Be(true); okay2.Should().Be(true);
}); });
[UnityTest]
public IEnumerator LoopTest() => UniTask.ToCoroutine(async () =>
{
for (int i = 0; i < 20; ++i)
{
UniTask.DelayFrame(100).Forget();
await UniTask.DelayFrame(1);
}
});
} }
} }

View File

@@ -37,6 +37,7 @@ namespace Cysharp.Threading.TasksTests
{ {
#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) #if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))
#if !UNITY_WSA #if !UNITY_WSA
#if !UNITY_WEBGL
//[UnityTest] //[UnityTest]
//public IEnumerator RunThread() => UniTask.ToCoroutine(async () => //public IEnumerator RunThread() => UniTask.ToCoroutine(async () =>
@@ -88,7 +89,7 @@ namespace Cysharp.Threading.TasksTests
} }
}); });
#endif
#endif #endif
#endif #endif
} }

View File

@@ -543,7 +543,7 @@ PlayerSettings:
platformArchitecture: {} platformArchitecture: {}
scriptingBackend: scriptingBackend:
Android: 1 Android: 1
Standalone: 0 Standalone: 1
il2cppCompilerConfiguration: {} il2cppCompilerConfiguration: {}
managedStrippingLevel: {} managedStrippingLevel: {}
incrementalIl2cppBuild: {} incrementalIl2cppBuild: {}