mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-20 06:00:11 +00:00
Compare commits
25 Commits
2.5.8
...
12df2b2e35
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
12df2b2e35 | ||
|
|
16895054f1 | ||
|
|
d3e71502d6 | ||
|
|
63708841f5 | ||
|
|
06067cd4c8 | ||
|
|
d9983cfe27 | ||
|
|
70eb7cd3ee | ||
|
|
cc3c70af90 | ||
|
|
8042b29ff8 | ||
|
|
b0d01ca75f | ||
|
|
7a63ab7088 | ||
|
|
bdf102f145 | ||
|
|
41cea030ab | ||
|
|
f9fd769be7 | ||
|
|
579304fe47 | ||
|
|
740ca7ef01 | ||
|
|
7c0f199fe0 | ||
|
|
9a3ec31533 | ||
|
|
37d8f4f48e | ||
|
|
27a0c06ede | ||
|
|
e4082ecd75 | ||
|
|
3b0fd784ff | ||
|
|
dc9ebfd765 | ||
|
|
005c83fbd7 | ||
|
|
eaa553dc83 |
5
.github/dependabot.yaml
vendored
5
.github/dependabot.yaml
vendored
@@ -5,3 +5,8 @@ updates:
|
|||||||
directory: "/"
|
directory: "/"
|
||||||
schedule:
|
schedule:
|
||||||
interval: "weekly" # Check for updates to GitHub Actions every week
|
interval: "weekly" # Check for updates to GitHub Actions every week
|
||||||
|
ignore:
|
||||||
|
# I just want update action when major/minor version is updated. patch updates are too noisy.
|
||||||
|
- dependency-name: '*'
|
||||||
|
update-types:
|
||||||
|
- version-update:semver-patch
|
||||||
|
|||||||
26
.github/workflows/build-debug.yml
vendored
26
.github/workflows/build-debug.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||||
- run: dotnet build -c Debug
|
- run: dotnet build -c Debug
|
||||||
- run: dotnet test -c Debug
|
- run: dotnet test -c Debug
|
||||||
@@ -24,27 +24,27 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 2
|
max-parallel: 2
|
||||||
matrix:
|
matrix:
|
||||||
unity: ["2021.3.41f1", "2022.3.39f1", "6000.0.12f1"] # Test with LTS
|
unity: ["2022.3.39f1", "6000.0.12f1"] # Test with LTS
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 20
|
timeout-minutes: 30 # Unity build takes more than 20min.
|
||||||
steps:
|
steps:
|
||||||
- name: Load secrets
|
- name: Load secrets
|
||||||
id: op-load-secret
|
id: op-load-secret
|
||||||
uses: 1password/load-secrets-action@v2
|
uses: 1password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0 # v2.0.0
|
||||||
with:
|
with:
|
||||||
export-env: false
|
export-env: false
|
||||||
env:
|
env:
|
||||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
|
|
||||||
# Execute scripts: Export Package
|
# Execute scripts: Export Package
|
||||||
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||||
- name: Build Unity (.unitypacakge)
|
- name: Build Unity (.unitypacakge)
|
||||||
if: ${{ startsWith(matrix.unity, '2021') }} # only execute once
|
if: ${{ startsWith(matrix.unity, '2022') }} # only execute once
|
||||||
uses: Cysharp/Actions/.github/actions/unity-builder@main
|
uses: Cysharp/Actions/.github/actions/unity-builder@main
|
||||||
env:
|
env:
|
||||||
UNITY_EMAIL: ${{ steps.op-load-secret.outputs.UNITY_EMAIL }}
|
UNITY_EMAIL: ${{ steps.op-load-secret.outputs.UNITY_EMAIL }}
|
||||||
@@ -56,10 +56,6 @@ jobs:
|
|||||||
targetPlatform: StandaloneLinux64
|
targetPlatform: StandaloneLinux64
|
||||||
buildMethod: PackageExporter.Export
|
buildMethod: PackageExporter.Export
|
||||||
|
|
||||||
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
|
||||||
with:
|
|
||||||
directory: src/UniTask
|
|
||||||
|
|
||||||
# Execute UnitTest
|
# Execute UnitTest
|
||||||
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend IL2CPP /BuildTarget StandaloneLinux64
|
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend IL2CPP /BuildTarget StandaloneLinux64
|
||||||
- name: Build UnitTest (IL2CPP)
|
- name: Build UnitTest (IL2CPP)
|
||||||
@@ -79,6 +75,10 @@ jobs:
|
|||||||
- name: Execute UnitTest
|
- name: Execute UnitTest
|
||||||
run: ./src/UniTask/bin/UnitTest/StandaloneLinux64_IL2CPP/test
|
run: ./src/UniTask/bin/UnitTest/StandaloneLinux64_IL2CPP/test
|
||||||
|
|
||||||
|
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
||||||
|
with:
|
||||||
|
directory: src/UniTask
|
||||||
|
|
||||||
# Store artifacts.
|
# Store artifacts.
|
||||||
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
|
- uses: Cysharp/Actions/.github/actions/upload-artifact@main
|
||||||
if: ${{ startsWith(matrix.unity, '2021') }} # only execute 2021
|
if: ${{ startsWith(matrix.unity, '2021') }} # only execute 2021
|
||||||
|
|||||||
10
.github/workflows/build-docs.yml
vendored
10
.github/workflows/build-docs.yml
vendored
@@ -11,21 +11,21 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
with:
|
with:
|
||||||
repository: Cysharp/DocfxTemplate
|
repository: Cysharp/DocfxTemplate
|
||||||
path: docs/_DocfxTemplate
|
path: docs/_DocfxTemplate
|
||||||
- uses: Kirbyrawr/docfx-action@master
|
- uses: Kirbyrawr/docfx-action@db9a22c8fe1e8693a2a21be54cb0b87dfaa72cc4
|
||||||
name: Docfx metadata
|
name: Docfx metadata
|
||||||
with:
|
with:
|
||||||
args: metadata docs/docfx.json
|
args: metadata docs/docfx.json
|
||||||
- uses: Kirbyrawr/docfx-action@master
|
- uses: Kirbyrawr/docfx-action@db9a22c8fe1e8693a2a21be54cb0b87dfaa72cc4
|
||||||
name: Docfx build
|
name: Docfx build
|
||||||
with:
|
with:
|
||||||
args: build docs/docfx.json
|
args: build docs/docfx.json
|
||||||
- name: Publish to GitHub Pages
|
- name: Publish to GitHub Pages
|
||||||
uses: peaceiris/actions-gh-pages@v4
|
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
publish_dir: docs/_site
|
publish_dir: docs/_site
|
||||||
|
|||||||
12
.github/workflows/build-release.yml
vendored
12
.github/workflows/build-release.yml
vendored
@@ -26,7 +26,7 @@ jobs:
|
|||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||||
@@ -51,17 +51,17 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Load secrets
|
- name: Load secrets
|
||||||
id: op-load-secret
|
id: op-load-secret
|
||||||
uses: 1password/load-secrets-action@v2
|
uses: 1password/load-secrets-action@581a835fb51b8e7ec56b71cf2ffddd7e68bb25e0 # v2.0.0
|
||||||
with:
|
with:
|
||||||
export-env: false
|
export-env: false
|
||||||
env:
|
env:
|
||||||
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN_PUBLIC }}
|
||||||
UNITY_EMAIL: "op://GitHubActionsPublic/UNITY_LICENSE/username"
|
UNITY_EMAIL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/username"
|
||||||
UNITY_PASSWORD: "op://GitHubActionsPublic/UNITY_LICENSE/credential"
|
UNITY_PASSWORD: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/credential"
|
||||||
UNITY_SERIAL: "op://GitHubActionsPublic/UNITY_LICENSE/serial"
|
UNITY_SERIAL: "op://${{ vars.OP_VAULT_ACTIONS_PUBLIC }}/UNITY_LICENSE/serial"
|
||||||
|
|
||||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/checkout@v4
|
- uses: Cysharp/Actions/.github/actions/checkout@main
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||||
# Execute scripts: Export Package
|
# Execute scripts: Export Package
|
||||||
|
|||||||
9
.github/workflows/toc.yml
vendored
9
.github/workflows/toc.yml
vendored
@@ -8,8 +8,7 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
generateTOC:
|
generateTOC:
|
||||||
name: TOC Generator
|
name: TOC Generator
|
||||||
runs-on: ubuntu-latest
|
uses: Cysharp/Actions/.github/workflows/toc-generator.yaml@main
|
||||||
steps:
|
with:
|
||||||
- uses: technote-space/toc-generator@v4.3.1
|
TOC_TITLE: "## Table of Contents"
|
||||||
with:
|
secrets: inherit
|
||||||
TOC_TITLE: "## Table of Contents"
|
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -33,6 +33,7 @@ For advanced tips, see blog post: [Extends UnityWebRequest via async decorator p
|
|||||||
- [AsyncEnumerable and Async LINQ](#asyncenumerable-and-async-linq)
|
- [AsyncEnumerable and Async LINQ](#asyncenumerable-and-async-linq)
|
||||||
- [Awaitable Events](#awaitable-events)
|
- [Awaitable Events](#awaitable-events)
|
||||||
- [Channel](#channel)
|
- [Channel](#channel)
|
||||||
|
- [vs Awaitable](#vs-awaitable)
|
||||||
- [For Unit Testing](#for-unit-testing)
|
- [For Unit Testing](#for-unit-testing)
|
||||||
- [ThreadPool limitation](#threadpool-limitation)
|
- [ThreadPool limitation](#threadpool-limitation)
|
||||||
- [IEnumerator.ToUniTask limitation](#ienumeratortounitask-limitation)
|
- [IEnumerator.ToUniTask limitation](#ienumeratortounitask-limitation)
|
||||||
@@ -67,6 +68,7 @@ async UniTask<string> DemoAsync()
|
|||||||
await SceneManager.LoadSceneAsync("scene2");
|
await SceneManager.LoadSceneAsync("scene2");
|
||||||
|
|
||||||
// .WithCancellation enables Cancel, GetCancellationTokenOnDestroy synchornizes with lifetime of GameObject
|
// .WithCancellation enables Cancel, GetCancellationTokenOnDestroy synchornizes with lifetime of GameObject
|
||||||
|
// after Unity 2022.2, you can use `destroyCancellationToken` in MonoBehaviour
|
||||||
var asset2 = await Resources.LoadAsync<TextAsset>("bar").WithCancellation(this.GetCancellationTokenOnDestroy());
|
var asset2 = await Resources.LoadAsync<TextAsset>("bar").WithCancellation(this.GetCancellationTokenOnDestroy());
|
||||||
|
|
||||||
// .ToUniTask accepts progress callback(and all options), Progress.Create is a lightweight alternative of IProgress<T>
|
// .ToUniTask accepts progress callback(and all options), Progress.Create is a lightweight alternative of IProgress<T>
|
||||||
@@ -293,6 +295,8 @@ public class MyBehaviour : MonoBehaviour
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
After Unity 2022.2, Unity adds CancellationToken in [MonoBehaviour.destroyCancellationToken](https://docs.unity3d.com/ScriptReference/MonoBehaviour-destroyCancellationToken.html) and [Application.exitCancellationToken](https://docs.unity3d.com/ScriptReference/Application-exitCancellationToken.html).
|
||||||
|
|
||||||
When cancellation is detected, all methods throw `OperationCanceledException` and propagate upstream. When exception(not limited to `OperationCanceledException`) is not handled in async method, it is propagated finally to `UniTaskScheduler.UnobservedTaskException`. The default behaviour of received unhandled exception is to write log as exception. Log level can be changed using `UniTaskScheduler.UnobservedExceptionWriteLogType`. If you want to use custom behaviour, set an action to `UniTaskScheduler.UnobservedTaskException.`
|
When cancellation is detected, all methods throw `OperationCanceledException` and propagate upstream. When exception(not limited to `OperationCanceledException`) is not handled in async method, it is propagated finally to `UniTaskScheduler.UnobservedTaskException`. The default behaviour of received unhandled exception is to write log as exception. Log level can be changed using `UniTaskScheduler.UnobservedExceptionWriteLogType`. If you want to use custom behaviour, set an action to `UniTaskScheduler.UnobservedTaskException.`
|
||||||
|
|
||||||
And also `OperationCanceledException` is a special exception, this is silently ignored at `UnobservedTaskException`.
|
And also `OperationCanceledException` is a special exception, this is silently ignored at `UnobservedTaskException`.
|
||||||
@@ -953,6 +957,14 @@ public class AsyncMessageBroker<T> : IDisposable
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
vs Awaitable
|
||||||
|
---
|
||||||
|
Unity 6 introduces the awaitable type, [Awaitable](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Awaitable.html). To put it simply, Awaitable can be considered a subset of UniTask, and in fact, Awaitable's design was influenced by UniTask. It should be able to handle PlayerLoop-based awaits, pooled Tasks, and support for cancellation with `CancellationToken` in a similar way. With its inclusion in the standard library, you may wonder whether to continue using UniTask or migrate to Awaitable. Here's a brief guide.
|
||||||
|
|
||||||
|
First, the functionality provided by Awaitable is equivalent to what coroutines offer. Instead of `yield return`, you use await; `await NextFrameAsync()` replaces `yield return null`; and there are equivalents for `WaitForSeconds` and `EndOfFrame`. However, that's the extent of it. Being coroutine-based in terms of functionality, it lacks Task-based features. In practical application development using async/await, operations like `WhenAll` are essential. Additionally, UniTask enables many frame-based operations (such as `DelayFrame`) and more flexible PlayerLoopTiming control, which are not available in Awaitable. Of course, there's no Tracker Window either.
|
||||||
|
|
||||||
|
Therefore, I recommend using UniTask for application development. UniTask is a superset of Awaitable and includes many essential features. For library development, where you want to avoid external dependencies, using Awaitable as a return type for methods would be appropriate. Awaitable can be converted to UniTask using `AsUniTask`, so there's no issue in handling Awaitable-based functionality within the UniTask library. Of course, if you don't need to worry about dependencies, using UniTask would be the best choice even for library development.
|
||||||
|
|
||||||
For Unit Testing
|
For Unit Testing
|
||||||
---
|
---
|
||||||
Unity's `[UnityTest]` attribute can test coroutine(IEnumerator) but can not test async. `UniTask.ToCoroutine` bridges async/await to coroutine so you can test async methods.
|
Unity's `[UnityTest]` attribute can test coroutine(IEnumerator) but can not test async. `UniTask.ToCoroutine` bridges async/await to coroutine so you can test async methods.
|
||||||
|
|||||||
468
README_CN.md
468
README_CN.md
File diff suppressed because it is too large
Load Diff
@@ -67,13 +67,13 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return (UniTask.FromCanceled(cancellationToken), default(CancellationTokenRegistration));
|
return (UniTask.FromCanceled(cancellationToken), default(CancellationTokenRegistration));
|
||||||
}
|
}
|
||||||
|
|
||||||
var promise = new UniTaskCompletionSource();
|
var promise = AutoResetUniTaskCompletionSource.Create();
|
||||||
return (promise.Task, cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
return (promise.Task, cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Callback(object state)
|
static void Callback(object state)
|
||||||
{
|
{
|
||||||
var promise = (UniTaskCompletionSource)state;
|
var promise = (AutoResetUniTaskCompletionSource)state;
|
||||||
promise.TrySetResult();
|
promise.TrySetResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
readonly Queue<T> items;
|
readonly Queue<T> items;
|
||||||
readonly SingleConsumerUnboundedChannelReader readerSource;
|
readonly SingleConsumerUnboundedChannelReader readerSource;
|
||||||
UniTaskCompletionSource completedTaskSource;
|
AutoResetUniTaskCompletionSource completedTaskSource;
|
||||||
UniTask completedTask;
|
UniTask completedTask;
|
||||||
|
|
||||||
Exception completionError;
|
Exception completionError;
|
||||||
@@ -208,7 +208,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return parent.completedTask;
|
return parent.completedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
parent.completedTaskSource = new UniTaskCompletionSource();
|
parent.completedTaskSource = AutoResetUniTaskCompletionSource.Create();
|
||||||
return parent.completedTaskSource.Task;
|
return parent.completedTaskSource.Task;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
public UniTask<bool> MoveNextAsync()
|
public UniTask<bool> MoveNextAsync()
|
||||||
{
|
{
|
||||||
var tcs = new UniTaskCompletionSource<bool>();
|
var tcs = AutoResetUniTaskCompletionSource<bool>.Create();
|
||||||
|
|
||||||
cancellationToken.Register(state =>
|
cancellationToken.Register(state =>
|
||||||
{
|
{
|
||||||
var task = (UniTaskCompletionSource<bool>)state;
|
var task = (AutoResetUniTaskCompletionSource<bool>)state;
|
||||||
task.TrySetCanceled(cancellationToken);
|
task.TrySetCanceled(cancellationToken);
|
||||||
}, tcs);
|
}, tcs);
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,13 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
/// <summary>This CancellationToken is canceled when the GameObject will be destroyed.</summary>
|
||||||
public static CancellationToken GetCancellationTokenOnDestroy(this GameObject gameObject)
|
public static CancellationToken GetCancellationTokenOnDestroy(this GameObject gameObject)
|
||||||
{
|
{
|
||||||
return gameObject.GetAsyncDestroyTrigger().CancellationToken;
|
return gameObject.GetAsyncDestroyTrigger().CancellationToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
/// <summary>This CancellationToken is canceled when the Component will be destroyed.</summary>
|
||||||
public static CancellationToken GetCancellationTokenOnDestroy(this Component component)
|
public static CancellationToken GetCancellationTokenOnDestroy(this Component component)
|
||||||
{
|
{
|
||||||
#if UNITY_2022_2_OR_NEWER
|
#if UNITY_2022_2_OR_NEWER
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
public WhenEachResult(Exception exception)
|
public WhenEachResult(Exception exception)
|
||||||
{
|
{
|
||||||
if (exception == null) throw new ArgumentNullException(nameof(exception));
|
if (exception == null) throw new ArgumentNullException(nameof(exception));
|
||||||
this.Result = default!;
|
this.Result = default;
|
||||||
this.Exception = exception;
|
this.Exception = exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,24 +144,24 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
RunWhenEachTask(self, array[i], length).Forget();
|
RunWhenEachTask(self, array[i], length).Forget();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static async UniTaskVoid RunWhenEachTask(Enumerator self, UniTask<T> task, int length)
|
static async UniTaskVoid RunWhenEachTask(Enumerator self, UniTask<T> task, int length)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
try
|
var result = await task;
|
||||||
{
|
self.channel.Writer.TryWrite(new WhenEachResult<T>(result));
|
||||||
var result = await task;
|
}
|
||||||
self.channel.Writer.TryWrite(new WhenEachResult<T>(result));
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
catch (Exception ex)
|
self.channel.Writer.TryWrite(new WhenEachResult<T>(ex));
|
||||||
{
|
}
|
||||||
self.channel.Writer.TryWrite(new WhenEachResult<T>(ex));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Interlocked.Increment(ref self.completeCount) == length)
|
if (Interlocked.Increment(ref self.completeCount) == length)
|
||||||
{
|
{
|
||||||
self.state = WhenEachState.Completed;
|
self.state = WhenEachState.Completed;
|
||||||
self.channel.Writer.TryComplete();
|
self.channel.Writer.TryComplete();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,11 @@
|
|||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 7cac24fdda5112047a1cd3dd66b542c4
|
guid: 7cac24fdda5112047a1cd3dd66b542c4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ namespace Cysharp.Threading.Tasks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static UniTask<T> AsUniTask<T>(this Task<T> task, bool useCurrentSynchronizationContext = true)
|
public static UniTask<T> AsUniTask<T>(this Task<T> task, bool useCurrentSynchronizationContext = true)
|
||||||
{
|
{
|
||||||
var promise = new UniTaskCompletionSource<T>();
|
var promise = AutoResetUniTaskCompletionSource<T>.Create();
|
||||||
|
|
||||||
task.ContinueWith((x, state) =>
|
task.ContinueWith((x, state) =>
|
||||||
{
|
{
|
||||||
var p = (UniTaskCompletionSource<T>)state;
|
var p = (AutoResetUniTaskCompletionSource<T>)state;
|
||||||
|
|
||||||
switch (x.Status)
|
switch (x.Status)
|
||||||
{
|
{
|
||||||
@@ -46,11 +46,11 @@ namespace Cysharp.Threading.Tasks
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true)
|
public static UniTask AsUniTask(this Task task, bool useCurrentSynchronizationContext = true)
|
||||||
{
|
{
|
||||||
var promise = new UniTaskCompletionSource();
|
var promise = AutoResetUniTaskCompletionSource.Create();
|
||||||
|
|
||||||
task.ContinueWith((x, state) =>
|
task.ContinueWith((x, state) =>
|
||||||
{
|
{
|
||||||
var p = (UniTaskCompletionSource)state;
|
var p = (AutoResetUniTaskCompletionSource)state;
|
||||||
|
|
||||||
switch (x.Status)
|
switch (x.Status)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
public static UniTask<T> ToUniTask<T>(this IObservable<T> source, bool useFirstValue = false, CancellationToken cancellationToken = default)
|
public static UniTask<T> ToUniTask<T>(this IObservable<T> source, bool useFirstValue = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var promise = new UniTaskCompletionSource<T>();
|
var promise = AutoResetUniTaskCompletionSource<T>.Create();
|
||||||
var disposable = new SingleAssignmentDisposable();
|
var disposable = new SingleAssignmentDisposable();
|
||||||
|
|
||||||
var observer = useFirstValue
|
var observer = useFirstValue
|
||||||
@@ -109,7 +109,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
static readonly Action<object> callback = OnCanceled;
|
static readonly Action<object> callback = OnCanceled;
|
||||||
|
|
||||||
readonly UniTaskCompletionSource<T> promise;
|
readonly IPromise<T> promise;
|
||||||
readonly SingleAssignmentDisposable disposable;
|
readonly SingleAssignmentDisposable disposable;
|
||||||
readonly CancellationToken cancellationToken;
|
readonly CancellationToken cancellationToken;
|
||||||
readonly CancellationTokenRegistration registration;
|
readonly CancellationTokenRegistration registration;
|
||||||
@@ -117,7 +117,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
bool hasValue;
|
bool hasValue;
|
||||||
T latestValue;
|
T latestValue;
|
||||||
|
|
||||||
public ToUniTaskObserver(UniTaskCompletionSource<T> promise, SingleAssignmentDisposable disposable, CancellationToken cancellationToken)
|
public ToUniTaskObserver(IPromise<T> promise, SingleAssignmentDisposable disposable, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
this.promise = promise;
|
this.promise = promise;
|
||||||
this.disposable = disposable;
|
this.disposable = disposable;
|
||||||
@@ -180,14 +180,14 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
static readonly Action<object> callback = OnCanceled;
|
static readonly Action<object> callback = OnCanceled;
|
||||||
|
|
||||||
readonly UniTaskCompletionSource<T> promise;
|
readonly IPromise<T> promise;
|
||||||
readonly SingleAssignmentDisposable disposable;
|
readonly SingleAssignmentDisposable disposable;
|
||||||
readonly CancellationToken cancellationToken;
|
readonly CancellationToken cancellationToken;
|
||||||
readonly CancellationTokenRegistration registration;
|
readonly CancellationTokenRegistration registration;
|
||||||
|
|
||||||
bool hasValue;
|
bool hasValue;
|
||||||
|
|
||||||
public FirstValueToUniTaskObserver(UniTaskCompletionSource<T> promise, SingleAssignmentDisposable disposable, CancellationToken cancellationToken)
|
public FirstValueToUniTaskObserver(IPromise<T> promise, SingleAssignmentDisposable disposable, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
this.promise = promise;
|
this.promise = promise;
|
||||||
this.disposable = disposable;
|
this.disposable = disposable;
|
||||||
|
|||||||
@@ -0,0 +1,386 @@
|
|||||||
|
// AsyncInstantiateOperation was added since Unity 2022.3.20 / 2023.3.0b7
|
||||||
|
#if UNITY_2022_3 && !(UNITY_2022_3_0 || UNITY_2022_3_1 || UNITY_2022_3_2 || UNITY_2022_3_3 || UNITY_2022_3_4 || UNITY_2022_3_5 || UNITY_2022_3_6 || UNITY_2022_3_7 || UNITY_2022_3_8 || UNITY_2022_3_9 || UNITY_2022_3_10 || UNITY_2022_3_11 || UNITY_2022_3_12 || UNITY_2022_3_13 || UNITY_2022_3_14 || UNITY_2022_3_15 || UNITY_2022_3_16 || UNITY_2022_3_17 || UNITY_2022_3_18 || UNITY_2022_3_19)
|
||||||
|
#define UNITY_2022_SUPPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2022_SUPPORT || UNITY_2023_3_OR_NEWER
|
||||||
|
|
||||||
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.Tasks
|
||||||
|
{
|
||||||
|
public static class AsyncInstantiateOperationExtensions
|
||||||
|
{
|
||||||
|
// AsyncInstantiateOperation<T> has GetAwaiter so no need to impl
|
||||||
|
// public static UniTask<T[]>.Awaiter GetAwaiter<T>(this AsyncInstantiateOperation<T> operation) where T : Object
|
||||||
|
|
||||||
|
public static UniTask<UnityEngine.Object[]> WithCancellation<T>(this AsyncInstantiateOperation asyncOperation, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return ToUniTask(asyncOperation, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<UnityEngine.Object[]> WithCancellation<T>(this AsyncInstantiateOperation asyncOperation, CancellationToken cancellationToken, bool cancelImmediately)
|
||||||
|
{
|
||||||
|
return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<UnityEngine.Object[]> ToUniTask(this AsyncInstantiateOperation asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||||
|
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled<UnityEngine.Object[]>(cancellationToken);
|
||||||
|
if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.Result);
|
||||||
|
return new UniTask<UnityEngine.Object[]>(AsyncInstantiateOperationConfiguredSource.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<T[]> WithCancellation<T>(this AsyncInstantiateOperation<T> asyncOperation, CancellationToken cancellationToken)
|
||||||
|
where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
return ToUniTask(asyncOperation, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<T[]> WithCancellation<T>(this AsyncInstantiateOperation<T> asyncOperation, CancellationToken cancellationToken, bool cancelImmediately)
|
||||||
|
where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
return ToUniTask(asyncOperation, cancellationToken: cancellationToken, cancelImmediately: cancelImmediately);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UniTask<T[]> ToUniTask<T>(this AsyncInstantiateOperation<T> asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken), bool cancelImmediately = false)
|
||||||
|
where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||||
|
if (cancellationToken.IsCancellationRequested) return UniTask.FromCanceled<T[]>(cancellationToken);
|
||||||
|
if (asyncOperation.isDone) return UniTask.FromResult(asyncOperation.Result);
|
||||||
|
return new UniTask<T[]>(AsyncInstantiateOperationConfiguredSource<T>.Create(asyncOperation, timing, progress, cancellationToken, cancelImmediately, out var token), token);
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class AsyncInstantiateOperationConfiguredSource : IUniTaskSource<UnityEngine.Object[]>, IPlayerLoopItem, ITaskPoolNode<AsyncInstantiateOperationConfiguredSource>
|
||||||
|
{
|
||||||
|
static TaskPool<AsyncInstantiateOperationConfiguredSource> pool;
|
||||||
|
AsyncInstantiateOperationConfiguredSource nextNode;
|
||||||
|
public ref AsyncInstantiateOperationConfiguredSource NextNode => ref nextNode;
|
||||||
|
|
||||||
|
static AsyncInstantiateOperationConfiguredSource()
|
||||||
|
{
|
||||||
|
TaskPool.RegisterSizeGetter(typeof(AsyncInstantiateOperationConfiguredSource), () => pool.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncInstantiateOperation asyncOperation;
|
||||||
|
IProgress<float> progress;
|
||||||
|
CancellationToken cancellationToken;
|
||||||
|
CancellationTokenRegistration cancellationTokenRegistration;
|
||||||
|
bool cancelImmediately;
|
||||||
|
bool completed;
|
||||||
|
|
||||||
|
UniTaskCompletionSourceCore<UnityEngine.Object[]> core;
|
||||||
|
|
||||||
|
Action<AsyncOperation> continuationAction;
|
||||||
|
|
||||||
|
AsyncInstantiateOperationConfiguredSource()
|
||||||
|
{
|
||||||
|
continuationAction = Continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IUniTaskSource<UnityEngine.Object[]> Create(AsyncInstantiateOperation asyncOperation, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
return AutoResetUniTaskCompletionSource<UnityEngine.Object[]>.CreateFromCanceled(cancellationToken, out token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pool.TryPop(out var result))
|
||||||
|
{
|
||||||
|
result = new AsyncInstantiateOperationConfiguredSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.asyncOperation = asyncOperation;
|
||||||
|
result.progress = progress;
|
||||||
|
result.cancellationToken = cancellationToken;
|
||||||
|
result.cancelImmediately = cancelImmediately;
|
||||||
|
result.completed = false;
|
||||||
|
|
||||||
|
asyncOperation.completed += result.continuationAction;
|
||||||
|
|
||||||
|
if (cancelImmediately && cancellationToken.CanBeCanceled)
|
||||||
|
{
|
||||||
|
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
|
||||||
|
{
|
||||||
|
var source = (AsyncInstantiateOperationConfiguredSource)state;
|
||||||
|
source.core.TrySetCanceled(source.cancellationToken);
|
||||||
|
}, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
|
|
||||||
|
token = result.core.Version;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnityEngine.Object[] GetResult(short token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return core.GetResult(token);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IUniTaskSource.GetResult(short token)
|
||||||
|
{
|
||||||
|
GetResult(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token)
|
||||||
|
{
|
||||||
|
return core.GetStatus(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus()
|
||||||
|
{
|
||||||
|
return core.UnsafeGetStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
// Already completed
|
||||||
|
if (completed || asyncOperation == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled(cancellationToken);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
progress.Report(asyncOperation.progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asyncOperation.isDone)
|
||||||
|
{
|
||||||
|
core.TrySetResult(asyncOperation.Result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryReturn()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
core.Reset();
|
||||||
|
asyncOperation.completed -= continuationAction;
|
||||||
|
asyncOperation = default;
|
||||||
|
progress = default;
|
||||||
|
cancellationToken = default;
|
||||||
|
cancellationTokenRegistration.Dispose();
|
||||||
|
cancelImmediately = default;
|
||||||
|
return pool.TryPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Continuation(AsyncOperation _)
|
||||||
|
{
|
||||||
|
if (completed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
completed = true;
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled(cancellationToken);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
core.TrySetResult(asyncOperation.Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class AsyncInstantiateOperationConfiguredSource<T> : IUniTaskSource<T[]>, IPlayerLoopItem, ITaskPoolNode<AsyncInstantiateOperationConfiguredSource<T>>
|
||||||
|
where T : UnityEngine.Object
|
||||||
|
{
|
||||||
|
static TaskPool<AsyncInstantiateOperationConfiguredSource<T>> pool;
|
||||||
|
AsyncInstantiateOperationConfiguredSource<T> nextNode;
|
||||||
|
public ref AsyncInstantiateOperationConfiguredSource<T> NextNode => ref nextNode;
|
||||||
|
|
||||||
|
static AsyncInstantiateOperationConfiguredSource()
|
||||||
|
{
|
||||||
|
TaskPool.RegisterSizeGetter(typeof(AsyncInstantiateOperationConfiguredSource<T>), () => pool.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncInstantiateOperation<T> asyncOperation;
|
||||||
|
IProgress<float> progress;
|
||||||
|
CancellationToken cancellationToken;
|
||||||
|
CancellationTokenRegistration cancellationTokenRegistration;
|
||||||
|
bool cancelImmediately;
|
||||||
|
bool completed;
|
||||||
|
|
||||||
|
UniTaskCompletionSourceCore<T[]> core;
|
||||||
|
|
||||||
|
Action<AsyncOperation> continuationAction;
|
||||||
|
|
||||||
|
AsyncInstantiateOperationConfiguredSource()
|
||||||
|
{
|
||||||
|
continuationAction = Continuation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IUniTaskSource<T[]> Create(AsyncInstantiateOperation<T> asyncOperation, PlayerLoopTiming timing, IProgress<float> progress, CancellationToken cancellationToken, bool cancelImmediately, out short token)
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
return AutoResetUniTaskCompletionSource<T[]>.CreateFromCanceled(cancellationToken, out token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pool.TryPop(out var result))
|
||||||
|
{
|
||||||
|
result = new AsyncInstantiateOperationConfiguredSource<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.asyncOperation = asyncOperation;
|
||||||
|
result.progress = progress;
|
||||||
|
result.cancellationToken = cancellationToken;
|
||||||
|
result.cancelImmediately = cancelImmediately;
|
||||||
|
result.completed = false;
|
||||||
|
|
||||||
|
asyncOperation.completed += result.continuationAction;
|
||||||
|
|
||||||
|
if (cancelImmediately && cancellationToken.CanBeCanceled)
|
||||||
|
{
|
||||||
|
result.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(state =>
|
||||||
|
{
|
||||||
|
var source = (AsyncInstantiateOperationConfiguredSource<T>)state;
|
||||||
|
source.core.TrySetCanceled(source.cancellationToken);
|
||||||
|
}, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
|
PlayerLoopHelper.AddAction(timing, result);
|
||||||
|
|
||||||
|
token = result.core.Version;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T[] GetResult(short token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return core.GetResult(token);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (!(cancelImmediately && cancellationToken.IsCancellationRequested))
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void IUniTaskSource.GetResult(short token)
|
||||||
|
{
|
||||||
|
GetResult(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus GetStatus(short token)
|
||||||
|
{
|
||||||
|
return core.GetStatus(token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UniTaskStatus UnsafeGetStatus()
|
||||||
|
{
|
||||||
|
return core.UnsafeGetStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnCompleted(Action<object> continuation, object state, short token)
|
||||||
|
{
|
||||||
|
core.OnCompleted(continuation, state, token);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool MoveNext()
|
||||||
|
{
|
||||||
|
// Already completed
|
||||||
|
if (completed || asyncOperation == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled(cancellationToken);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (progress != null)
|
||||||
|
{
|
||||||
|
progress.Report(asyncOperation.progress);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asyncOperation.isDone)
|
||||||
|
{
|
||||||
|
core.TrySetResult(asyncOperation.Result);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryReturn()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
core.Reset();
|
||||||
|
asyncOperation.completed -= continuationAction;
|
||||||
|
asyncOperation = default;
|
||||||
|
progress = default;
|
||||||
|
cancellationToken = default;
|
||||||
|
cancellationTokenRegistration.Dispose();
|
||||||
|
cancelImmediately = default;
|
||||||
|
return pool.TryPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Continuation(AsyncOperation _)
|
||||||
|
{
|
||||||
|
if (completed)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
completed = true;
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled(cancellationToken);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
core.TrySetResult(asyncOperation.Result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8321f4244edfdcd4798b4fcc92a736c9
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "com.cysharp.unitask",
|
"name": "com.cysharp.unitask",
|
||||||
"displayName": "UniTask",
|
"displayName": "UniTask",
|
||||||
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
|
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
|
||||||
"version": "2.5.8",
|
"version": "2.5.10",
|
||||||
"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" ],
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ using UnityEngine.SceneManagement;
|
|||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
|
using UnityEngine.Events;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -172,13 +173,14 @@ public class SandboxMain : MonoBehaviour
|
|||||||
// var foo = InstantiateAsync<SandboxMain>(this).ToUniTask();
|
// var foo = InstantiateAsync<SandboxMain>(this).ToUniTask();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var tako = await foo;
|
// var tako = await foo;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//UnityAction action;
|
||||||
|
|
||||||
|
|
||||||
return 10;
|
return 10;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user