Compare commits

...

15 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
15 changed files with 148 additions and 77 deletions

View File

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

View File

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

View File

@@ -215,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.
Also `UniTaskCompletionSource` can await multipletimes and await from many caller.
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.
@@ -796,9 +798,11 @@ IEnumerator.ToUniTask limitation
---
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.
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
---
UniTask can run on Unity Edtitor like Editor Coroutine. However, there are some limitations.
@@ -854,7 +858,7 @@ Use UniTask type.
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
foreach (var (type, size) in TaskPool.GetCacheSizeInfo())
@@ -908,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`.
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#2.0.35`. For example `https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#2.0.35`.
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

View File

@@ -32,6 +32,19 @@ namespace Cysharp.Threading.Tasks
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>
{
static TaskPool<EnumeratorPromise> pool;
@@ -215,7 +228,7 @@ namespace Cysharp.Threading.Tasks
}
else
{
yield return null;
goto WARN;
}
}
else if (current is IEnumerator e3)
@@ -228,9 +241,15 @@ namespace Cysharp.Threading.Tasks
}
else
{
// WaitForEndOfFrame, WaitForFixedUpdate, others.
yield return null;
goto WARN;
}
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;
}
}
@@ -261,5 +280,4 @@ namespace Cysharp.Threading.Tasks
}
}
}
}
}

View File

@@ -223,6 +223,17 @@ namespace Cysharp.Threading.Tasks
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)
{
core.TrySetCanceled(cancellationToken);

View File

@@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.Internal
readonly PlayerLoopTiming timing;
SpinLock gate = new SpinLock();
SpinLock gate = new SpinLock(false);
bool dequing = false;
int actionListCount = 0;

View File

@@ -12,7 +12,9 @@ namespace Cysharp.Threading.Tasks
public static class TaskPool
{
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()
{
@@ -40,19 +42,24 @@ namespace Cysharp.Threading.Tasks
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)
{
sizes[type] = getSize;
lock (sizes)
{
sizes[type] = getSize;
}
}
}
public interface ITaskPoolNode<T>
{
ref T NextNode { get; }

View File

@@ -561,21 +561,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
awaiter.SourceOnCompleted(state =>
else
{
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)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
}, StateTuple.Create(awaiter));
}
}
public static void Forget(this UniTask task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
@@ -629,21 +631,23 @@ namespace Cysharp.Threading.Tasks
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
awaiter.SourceOnCompleted(state =>
else
{
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)
{
UniTaskScheduler.PublishUnobservedTaskException(ex);
}
}
}, StateTuple.Create(awaiter));
}, StateTuple.Create(awaiter));
}
}
public static void Forget<T>(this UniTask<T> task, Action<Exception> exceptionHandler, bool handleExceptionOnMainThread = true)
@@ -736,12 +740,12 @@ namespace Cysharp.Threading.Tasks
{
await await task;
}
public static async UniTask<T> Unwrap<T>(this Task<UniTask<T>> task)
{
return await await task;
}
public static async UniTask<T> Unwrap<T>(this Task<UniTask<T>> task, bool continueOnCapturedContext)
{
return await await task.ConfigureAwait(continueOnCapturedContext);
@@ -756,12 +760,12 @@ namespace Cysharp.Threading.Tasks
{
await await task.ConfigureAwait(continueOnCapturedContext);
}
public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task)
{
return await await task;
}
public static async UniTask<T> Unwrap<T>(this UniTask<Task<T>> task, bool continueOnCapturedContext)
{
return await (await task).ConfigureAwait(continueOnCapturedContext);

View File

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

View File

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

View File

@@ -507,8 +507,19 @@ public class SandboxMain : MonoBehaviour
CancellationTokenSource quitSource = new CancellationTokenSource();
IEnumerator TestCor()
{
Debug.Log("start cor");
yield return null;
yield return new WaitForEndOfFrame();
Debug.Log("end cor");
}
async UniTaskVoid Start()
{
await TestCor().ToUniTask(this);
Debug.Log("App Start");
Application.quitting += () =>

View File

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

View File

@@ -135,6 +135,8 @@ namespace Cysharp.Threading.TasksTests
l.Add(30);
}
#if !UNITY_WEBGL
[UnityTest]
public IEnumerator WaitForSecondsTest() => UniTask.ToCoroutine(async () =>
{
@@ -162,6 +164,8 @@ namespace Cysharp.Threading.TasksTests
yield return new WaitForSeconds(3.0f);
}
#endif
IEnumerator Worker(List<(int, int)> l)
{
l.Add((0, Time.frameCount));

View File

@@ -175,6 +175,7 @@ namespace Cysharp.Threading.TasksTests
}
});
#if !UNITY_WEBGL
[UnityTest]
public IEnumerator DelayInThreadPool() => UniTask.ToCoroutine(async () =>
@@ -185,6 +186,8 @@ namespace Cysharp.Threading.TasksTests
});
});
#endif
[UnityTest]
public IEnumerator DelayRealtime() => UniTask.ToCoroutine(async () =>
{

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 !UNITY_WSA
#if !UNITY_WEBGL
//[UnityTest]
//public IEnumerator RunThread() => UniTask.ToCoroutine(async () =>
@@ -88,7 +89,7 @@ namespace Cysharp.Threading.TasksTests
}
});
#endif
#endif
#endif
}