mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-15 11:30:09 +00:00
Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2245bc38b | ||
|
|
f092f6a112 | ||
|
|
ed617a04a6 | ||
|
|
340736795c | ||
|
|
dc804ffb13 | ||
|
|
a879989d1c | ||
|
|
ee54559532 | ||
|
|
4a72ec2a1a | ||
|
|
e999268305 | ||
|
|
8300c1b1e6 | ||
|
|
daa0c7b9a0 | ||
|
|
9b9a4ec76a | ||
|
|
3f8e43b83f | ||
|
|
cf6f0799e9 | ||
|
|
91ba4f003a | ||
|
|
f48cb4b03e | ||
|
|
70a243d978 | ||
|
|
9b95f3b9f6 | ||
|
|
a25adb601b | ||
|
|
e6240879c4 | ||
|
|
a94e8cceac | ||
|
|
0595a4182a | ||
|
|
df96c119c1 | ||
|
|
534f4a2588 | ||
|
|
873485ad1a | ||
|
|
78db78c7bd | ||
|
|
226e272787 | ||
|
|
9e2163616b | ||
|
|
52df6fbf3f | ||
|
|
33d32baea4 | ||
|
|
b0250cfe75 | ||
|
|
7a35f121cd | ||
|
|
79f1566fdb | ||
|
|
364b67805d | ||
|
|
62ca0c6e92 | ||
|
|
f63212aa17 | ||
|
|
768fd16e60 | ||
|
|
3c99010ba0 | ||
|
|
5c668717d8 | ||
|
|
b089f74c65 | ||
|
|
fcf4f21cc1 | ||
|
|
ee2fd3e91d | ||
|
|
27604496ca | ||
|
|
0d01034a57 | ||
|
|
50a67d8f41 | ||
|
|
2a23a85cdd | ||
|
|
e127d9976e | ||
|
|
c31b78e45e | ||
|
|
b6b0b4000d | ||
|
|
69be818a46 | ||
|
|
a1dee8b54f | ||
|
|
4f6166102d | ||
|
|
6b1d2c231a | ||
|
|
0715dd31bf | ||
|
|
26dbfa3655 | ||
|
|
6ac55e37a1 | ||
|
|
60bfbae787 | ||
|
|
fc9ddeb15c | ||
|
|
dfe18d11ff | ||
|
|
958a8e11ab | ||
|
|
257186313b | ||
|
|
5bd508b31c | ||
|
|
9e18ba332e | ||
|
|
946b9003f0 | ||
|
|
ffa55becf3 | ||
|
|
72e620d169 | ||
|
|
10ebddf892 | ||
|
|
c51e45ee21 | ||
|
|
6968faf35b | ||
|
|
4fc9ca315e | ||
|
|
aaf1c0eaa1 | ||
|
|
44ce3c96bb | ||
|
|
03097f08e2 | ||
|
|
af82dd719e | ||
|
|
ecd3625a08 | ||
|
|
da8f599ccb | ||
|
|
aa3216e48d | ||
|
|
5f7148419f | ||
|
|
89ae106ea7 | ||
|
|
721a7d9e4e | ||
|
|
18f2746f0d | ||
|
|
8a10f2191f | ||
|
|
8b3c8d15c4 | ||
|
|
49ca9364f7 | ||
|
|
62f6429b60 | ||
|
|
b6a9836e81 |
40
.github/workflows/build-debug.yml
vendored
40
.github/workflows/build-debug.yml
vendored
@@ -4,29 +4,26 @@ on:
|
|||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- "master"
|
- "master"
|
||||||
tags:
|
|
||||||
- "!*" # not a tag push
|
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- "master"
|
- "master"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-dotnet:
|
build-dotnet:
|
||||||
if: "!(contains(github.event.head_commit.message, '[skip ci]') || contains(github.event.head_commit.message, '[ci skip]'))"
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
timeout-minutes: 10
|
||||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
|
||||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
|
||||||
NUGET_XMLDOC_MODE: skip
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||||
with:
|
with:
|
||||||
dotnet-version: 3.1.x
|
dotnet-version: |
|
||||||
- run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj
|
3.1.x
|
||||||
|
6.0.x
|
||||||
|
- run: dotnet build -c Debug
|
||||||
|
- run: dotnet test -c Debug
|
||||||
|
|
||||||
build-unity:
|
build-unity:
|
||||||
if: "!(contains(github.event.head_commit.message, '[skip ci]') || contains(github.event.head_commit.message, '[ci skip]')) && ((github.event_name == 'push' && github.repository_owner == 'Cysharp') || startsWith(github.event.pull_request.head.label, 'Cysharp:'))"
|
if: "((github.event_name == 'push' && github.repository_owner == 'Cysharp') || startsWith(github.event.pull_request.head.label, 'Cysharp:'))"
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
unity: ["2019.3.9f1", "2019.4.13f1", "2020.1.12f1"]
|
unity: ["2019.3.9f1", "2019.4.13f1", "2020.1.12f1"]
|
||||||
@@ -38,12 +35,13 @@ jobs:
|
|||||||
- unity: 2020.1.12f1
|
- unity: 2020.1.12f1
|
||||||
license: UNITY_LICENSE_2020
|
license: UNITY_LICENSE_2020
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
# Execute scripts: RuntimeUnitTestToolkit
|
# Execute scripts: RuntimeUnitTestToolkit
|
||||||
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
|
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
|
||||||
- name: Build UnitTest(Linux64, mono)
|
- name: Build UnitTest(Linux64, mono)
|
||||||
uses: game-ci/unity-builder@v2.0-alpha-6
|
uses: game-ci/unity-builder@v2
|
||||||
env:
|
env:
|
||||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||||
with:
|
with:
|
||||||
@@ -59,7 +57,7 @@ jobs:
|
|||||||
# 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: Export unitypackage
|
- name: Export unitypackage
|
||||||
uses: game-ci/unity-builder@v2.0-alpha-6
|
uses: game-ci/unity-builder@v2
|
||||||
env:
|
env:
|
||||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||||
with:
|
with:
|
||||||
@@ -69,15 +67,9 @@ jobs:
|
|||||||
buildMethod: PackageExporter.Export
|
buildMethod: PackageExporter.Export
|
||||||
versioning: None
|
versioning: None
|
||||||
|
|
||||||
- name: check all .meta is commited
|
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
||||||
run: |
|
with:
|
||||||
if git ls-files --others --exclude-standard -t | grep --regexp='[.]meta$'; then
|
directory: src/UniTask
|
||||||
echo "Detected .meta file generated. Do you forgot commit a .meta file?"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "Great, all .meta files are commited."
|
|
||||||
fi
|
|
||||||
working-directory: src/UniTask
|
|
||||||
|
|
||||||
# Store artifacts.
|
# Store artifacts.
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v2
|
||||||
|
|||||||
8
.github/workflows/build-docs.yml
vendored
8
.github/workflows/build-docs.yml
vendored
@@ -8,11 +8,11 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
run-docfx:
|
run-docfx:
|
||||||
if: "!(contains(github.event.head_commit.message, '[skip ci]') || contains(github.event.head_commit.message, '[ci skip]'))"
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 10
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
repository: Cysharp/DocfxTemplate
|
repository: Cysharp/DocfxTemplate
|
||||||
path: docs/_DocfxTemplate
|
path: docs/_DocfxTemplate
|
||||||
@@ -28,4 +28,4 @@ jobs:
|
|||||||
uses: peaceiris/actions-gh-pages@v3
|
uses: peaceiris/actions-gh-pages@v3
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
publish_dir: docs/_site
|
publish_dir: docs/_site
|
||||||
|
|||||||
113
.github/workflows/build-release.yml
vendored
113
.github/workflows/build-release.yml
vendored
@@ -6,83 +6,44 @@ on:
|
|||||||
tag:
|
tag:
|
||||||
description: "tag: git tag you want create. (sample 1.0.0)"
|
description: "tag: git tag you want create. (sample 1.0.0)"
|
||||||
required: true
|
required: true
|
||||||
dry_run:
|
dry-run:
|
||||||
description: "dry_run: true will never create relase/nuget."
|
description: "dry-run: true will never create relase/nuget."
|
||||||
required: true
|
required: true
|
||||||
default: "false"
|
default: false
|
||||||
|
type: boolean
|
||||||
|
|
||||||
env:
|
env:
|
||||||
GIT_TAG: ${{ github.event.inputs.tag }}
|
GIT_TAG: ${{ github.event.inputs.tag }}
|
||||||
DRY_RUN: ${{ github.event.inputs.dry_run }}
|
DRY_RUN: ${{ github.event.inputs.dry-run }}
|
||||||
DRY_RUN_BRANCH_PREFIX: "test_release"
|
|
||||||
DOTNET_SDK_VERISON_3: 3.1.x
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-packagejson:
|
update-packagejson:
|
||||||
runs-on: ubuntu-latest
|
uses: Cysharp/Actions/.github/workflows/update-packagejson.yaml@main
|
||||||
env:
|
with:
|
||||||
TARGET_FILE: ./src/UniTask/Assets/Plugins/UniTask/package.json
|
file-path: ./src/UniTask/Assets/Plugins/UniTask/package.json
|
||||||
outputs:
|
tag: ${{ github.event.inputs.tag }}
|
||||||
sha: ${{ steps.commit.outputs.sha }}
|
dry-run: ${{ fromJson(github.event.inputs.dry-run) }}
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: before
|
|
||||||
run: cat ${{ env.TARGET_FILE}}
|
|
||||||
- name: update package.json to version ${{ env.GIT_TAG }}
|
|
||||||
run: sed -i -e "s/\(\"version\":\) \"\(.*\)\",/\1 \"${{ env.GIT_TAG }}\",/" ${{ env.TARGET_FILE }}
|
|
||||||
- name: after
|
|
||||||
run: cat ${{ env.TARGET_FILE}}
|
|
||||||
- name: Commit files
|
|
||||||
id: commit
|
|
||||||
run: |
|
|
||||||
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
||||||
git config --local user.name "github-actions[bot]"
|
|
||||||
git commit -m "feat: Update package.json to ${{ env.GIT_TAG }}" -a
|
|
||||||
echo "::set-output name=sha::$(git rev-parse HEAD)"
|
|
||||||
- name: check sha
|
|
||||||
run: echo "SHA ${SHA}"
|
|
||||||
env:
|
|
||||||
SHA: ${{ steps.commit.outputs.sha }}
|
|
||||||
- name: tag
|
|
||||||
run: git tag ${{ env.GIT_TAG }}
|
|
||||||
if: env.DRY_RUN == 'false'
|
|
||||||
- name: Push changes
|
|
||||||
uses: ad-m/github-push-action@master
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
branch: ${{ github.ref }}
|
|
||||||
tags: true
|
|
||||||
if: env.DRY_RUN == 'false'
|
|
||||||
- name: Push changes (dry_run)
|
|
||||||
uses: ad-m/github-push-action@master
|
|
||||||
with:
|
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
branch: ${{ env.DRY_RUN_BRANCH_PREFIX }}-${{ env.GIT_TAG }}
|
|
||||||
tags: false
|
|
||||||
if: env.DRY_RUN == 'true'
|
|
||||||
|
|
||||||
build-dotnet:
|
build-dotnet:
|
||||||
needs: [update-packagejson]
|
needs: [update-packagejson]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 10
|
timeout-minutes: 10
|
||||||
env:
|
|
||||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
|
||||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
|
||||||
NUGET_XMLDOC_MODE: skip
|
|
||||||
steps:
|
steps:
|
||||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/setup-dotnet@v1
|
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||||
with:
|
with:
|
||||||
dotnet-version: "${{ env.DOTNET_SDK_VERSION_3 }}"
|
dotnet-version: |
|
||||||
|
3.1.x
|
||||||
|
6.0.x
|
||||||
# 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 }}
|
||||||
- run: dotnet test -c Release --no-build
|
- run: dotnet test -c Release --no-build
|
||||||
- run: dotnet pack ./src/UniTask.NetCore/UniTask.NetCore.csproj -c Release --no-build -p:Version=${{ env.GIT_TAG }} -o ./publish
|
- run: dotnet pack ./src/UniTask.NetCore/UniTask.NetCore.csproj -c Release --no-build -p:Version=${{ env.GIT_TAG }} -o ./publish
|
||||||
# Store artifacts.
|
# Store artifacts.
|
||||||
- uses: actions/upload-artifact@v1
|
- uses: actions/upload-artifact@v2
|
||||||
with:
|
with:
|
||||||
name: nuget
|
name: nuget
|
||||||
path: ./publish/
|
path: ./publish/
|
||||||
@@ -99,13 +60,13 @@ jobs:
|
|||||||
timeout-minutes: 15
|
timeout-minutes: 15
|
||||||
steps:
|
steps:
|
||||||
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
- run: echo ${{ needs.update-packagejson.outputs.sha }}
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
ref: ${{ needs.update-packagejson.outputs.sha }}
|
ref: ${{ needs.update-packagejson.outputs.sha }}
|
||||||
# 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: Export unitypackage
|
- name: Export unitypackage
|
||||||
uses: game-ci/unity-builder@v2.0-alpha-6
|
uses: game-ci/unity-builder@v2
|
||||||
env:
|
env:
|
||||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||||
with:
|
with:
|
||||||
@@ -115,15 +76,9 @@ jobs:
|
|||||||
buildMethod: PackageExporter.Export
|
buildMethod: PackageExporter.Export
|
||||||
versioning: None
|
versioning: None
|
||||||
|
|
||||||
- name: check all .meta is commited
|
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
|
||||||
run: |
|
with:
|
||||||
if git ls-files --others --exclude-standard -t | grep --regexp='[.]meta$'; then
|
directory: src/UniTask
|
||||||
echo "Detected .meta file generated. Do you forgot commit a .meta file?"
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "Great, all .meta files are commited."
|
|
||||||
fi
|
|
||||||
working-directory: src/UniTask
|
|
||||||
|
|
||||||
# Store artifacts.
|
# Store artifacts.
|
||||||
- uses: actions/upload-artifact@v2
|
- uses: actions/upload-artifact@v2
|
||||||
@@ -132,18 +87,12 @@ jobs:
|
|||||||
path: ./src/UniTask/UniTask.${{ env.GIT_TAG }}.unitypackage
|
path: ./src/UniTask/UniTask.${{ env.GIT_TAG }}.unitypackage
|
||||||
|
|
||||||
create-release:
|
create-release:
|
||||||
if: github.event.inputs.dry_run == 'false'
|
if: github.event.inputs.dry-run == 'false'
|
||||||
needs: [update-packagejson, build-dotnet, build-unity]
|
needs: [update-packagejson, build-dotnet, build-unity]
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
timeout-minutes: 10
|
||||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
|
||||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
|
||||||
NUGET_XMLDOC_MODE: skip
|
|
||||||
steps:
|
steps:
|
||||||
# setup dotnet for nuget push
|
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
|
||||||
- uses: actions/setup-dotnet@v1
|
|
||||||
with:
|
|
||||||
dotnet-version: "${{ env.DOTNET_SDK_VERSION_3 }}"
|
|
||||||
# Create Releases
|
# Create Releases
|
||||||
- uses: actions/create-release@v1
|
- uses: actions/create-release@v1
|
||||||
id: create_release
|
id: create_release
|
||||||
@@ -170,12 +119,8 @@ jobs:
|
|||||||
asset_content_type: application/octet-stream
|
asset_content_type: application/octet-stream
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if: github.event.inputs.dry_run == 'true'
|
if: needs.update-packagejson.outputs.is-branch-created == 'true'
|
||||||
needs: [build-dotnet, build-unity]
|
needs: [update-packagejson, build-dotnet, build-unity]
|
||||||
runs-on: ubuntu-latest
|
uses: Cysharp/Actions/.github/workflows/clean-packagejson-branch.yaml@main
|
||||||
steps:
|
with:
|
||||||
- name: Delete branch
|
branch: ${{ needs.update-packagejson.outputs.branch-name }}
|
||||||
uses: dawidd6/action-delete-branch@v3
|
|
||||||
with:
|
|
||||||
github_token: ${{ github.token }}
|
|
||||||
branches: ${{ env.DRY_RUN_BRANCH_PREFIX }}-${{ env.GIT_TAG }}
|
|
||||||
|
|||||||
18
.github/workflows/stale.yml
vendored
18
.github/workflows/stale.yml
vendored
@@ -1,24 +1,10 @@
|
|||||||
name: "Close stale issues"
|
name: "Close stale issues"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * *"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
uses: Cysharp/Actions/.github/workflows/stale-issue.yaml@main
|
||||||
steps:
|
|
||||||
- uses: actions/stale@v3
|
|
||||||
with:
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
# enable issue
|
|
||||||
stale-issue-message: "This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days."
|
|
||||||
stale-issue-label: "stale"
|
|
||||||
# enable pr
|
|
||||||
stale-pr-message: "This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days."
|
|
||||||
stale-pr-label: "stale"
|
|
||||||
days-before-stale: 90
|
|
||||||
days-before-close: 7
|
|
||||||
exempt-issue-labels: "wip"
|
|
||||||
exempt-pr-labels: "wip"
|
|
||||||
remove-stale-when-updated: true
|
|
||||||
|
|||||||
111
README.md
111
README.md
@@ -86,8 +86,8 @@ async UniTask<string> DemoAsync()
|
|||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
await UniTask.NextFrame();
|
await UniTask.NextFrame();
|
||||||
|
|
||||||
// replacement of WaitForEndOfFrame(same as UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate))
|
// replacement of WaitForEndOfFrame(requires MonoBehaviour(CoroutineRunner))
|
||||||
await UniTask.WaitForEndOfFrame();
|
await UniTask.WaitForEndOfFrame(this); // this is MonoBehaviour
|
||||||
|
|
||||||
// replacement of yield return new WaitForFixedUpdate(same as UniTask.Yield(PlayerLoopTiming.FixedUpdate))
|
// replacement of yield return new WaitForFixedUpdate(same as UniTask.Yield(PlayerLoopTiming.FixedUpdate))
|
||||||
await UniTask.WaitForFixedUpdate();
|
await UniTask.WaitForFixedUpdate();
|
||||||
@@ -241,9 +241,57 @@ CancellationToken can be created by `CancellationTokenSource` or MonoBehaviour's
|
|||||||
await UniTask.DelayFrame(1000, cancellationToken: this.GetCancellationTokenOnDestroy());
|
await UniTask.DelayFrame(1000, cancellationToken: this.GetCancellationTokenOnDestroy());
|
||||||
```
|
```
|
||||||
|
|
||||||
When cancellation is detected, all methods throw `OperationCanceledException` and propagate upstream. `OperationCanceledException` is a special exception, if this exception is not handled, it is propagated finally to `UniTaskScheduler.UnobservedTaskException`.
|
For propagate Cancellation, all async method recommend to accept `CancellationToken cancellationToken` at last argument, and pass `CancellationToken` from root to end.
|
||||||
|
|
||||||
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.`
|
```csharp
|
||||||
|
await FooAsync(this.GetCancellationTokenOnDestroy());
|
||||||
|
|
||||||
|
// ---
|
||||||
|
|
||||||
|
async UniTask FooAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await BarAsync(cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
async UniTask BarAsync(CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await UniTask.Delay(TimeSpan.FromSeconds(3), cancellationToken);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`CancellationToken` means lifecycle of async. You can hold your own lifecycle insteadof default CancellationTokenOnDestroy.
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
public class MyBehaviour : MonoBehaviour
|
||||||
|
{
|
||||||
|
CancellationTokenSource disableCancellation = new CancellationTokenSource();
|
||||||
|
CancellationTokenSource destroyCancellation = new CancellationTokenSource();
|
||||||
|
|
||||||
|
private void OnEnable()
|
||||||
|
{
|
||||||
|
if (disableCancellation != null)
|
||||||
|
{
|
||||||
|
disableCancellation.Dispose();
|
||||||
|
}
|
||||||
|
disableCancellation = new CancellationTokenSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable()
|
||||||
|
{
|
||||||
|
disableCancellation.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDestroy()
|
||||||
|
{
|
||||||
|
destroyCancellation.Cancel();
|
||||||
|
destroyCancellation.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
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.`
|
||||||
|
|
||||||
|
Andalso `OperationCanceledException` is a special exception, this is silently ignored at `UnobservedTaskException`.
|
||||||
|
|
||||||
If you want to cancel behaviour in an async UniTask method, throw `OperationCanceledException` manually.
|
If you want to cancel behaviour in an async UniTask method, throw `OperationCanceledException` manually.
|
||||||
|
|
||||||
@@ -265,7 +313,7 @@ public async UniTask<int> BarAsync()
|
|||||||
var x = await FooAsync();
|
var x = await FooAsync();
|
||||||
return x * 2;
|
return x * 2;
|
||||||
}
|
}
|
||||||
catch (Exception ex) when (!(ex is OperationCanceledException))
|
catch (Exception ex) when (!(ex is OperationCanceledException)) // when (ex is not OperationCanceledException) at C# 9.0
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -448,17 +496,17 @@ public enum PlayerLoopTiming
|
|||||||
|
|
||||||
It indicates when to run, you can check [PlayerLoopList.md](https://gist.github.com/neuecc/bc3a1cfd4d74501ad057e49efcd7bdae) to Unity's default playerloop and injected UniTask's custom loop.
|
It indicates when to run, you can check [PlayerLoopList.md](https://gist.github.com/neuecc/bc3a1cfd4d74501ad057e49efcd7bdae) to Unity's default playerloop and injected UniTask's custom loop.
|
||||||
|
|
||||||
`PlayerLoopTiming.Update` is similar to `yield return null` in a 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 to `WaitForFixedUpdate`, `PlayerLoopTiming.LastPostLateUpdate` is similar to `WaitForEndOfFrame` in coroutine.
|
`PlayerLoopTiming.Update` is similar to `yield return null` in a 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 to `WaitForFixedUpdate`.
|
||||||
|
|
||||||
> `await UniTask.WaitForEndOfFrame()` is not equivalent 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) do not work correctly when replaced with async/await. In these cases, use a coroutine instead.
|
> `PlayerLoopTiming.LastPostLateUpdate` is not equivalent 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(`Texture2D.ReadPixels`, `ScreenCapture.CaptureScreenshotAsTexture`, `CommandBuffer`, etc) do not work correctly when replaced with async/await. In these cases, pass MonoBehaviour(coroutine runnner) to `UniTask.WaitForEndOfFrame`. For example, `await UniTask.WaitForEndOfFrame(this);` is lightweight allocation free alternative of `yield return new WaitForEndOfFrame()`.
|
||||||
|
|
||||||
`yield return null` and `UniTask.Yield` are similar but different. `yield return null` always returns next frame but `UniTask.Yield` returns next called. That is, call `UniTask.Yield(PlayerLoopTiming.Update)` on `PreUpdate`, it returns same frame. `UniTask.NextFrame()` guarantees return next frame, you can expect this to behave exactly the same as `yield return null`.
|
`yield return null` and `UniTask.Yield` are similar but different. `yield return null` always returns next frame but `UniTask.Yield` returns next called. That is, call `UniTask.Yield(PlayerLoopTiming.Update)` on `PreUpdate`, it returns same frame. `UniTask.NextFrame()` guarantees return next frame, you can expect this 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 fastest.
|
> UniTask.Yield(without CancellationToken) is a special type, returns `YieldAwaitable` and runs on YieldRunner. It is the most lightweight and fastest.
|
||||||
|
|
||||||
`AsyncOperation` is returned from native timing. For example, await `SceneManager.LoadSceneAsync` is returned from `EarlyUpdate.UpdatePreloading` and after being called, the loaded scene's `Start` is called from `EarlyUpdate.ScriptRunDelayedStartupFrame`. Also `await UnityWebRequest` is returned from `EarlyUpdate.ExecuteMainThreadJobs`.
|
`AsyncOperation` is returned from native timing. For example, await `SceneManager.LoadSceneAsync` is returned from `EarlyUpdate.UpdatePreloading` and after being called, the loaded scene's `Start` is called from `EarlyUpdate.ScriptRunDelayedStartupFrame`. Also `await UnityWebRequest` is returned from `EarlyUpdate.ExecuteMainThreadJobs`.
|
||||||
|
|
||||||
In UniTask, await directly uses native timing, `WithCancellation` and `ToUniTask` use specified timing. This is usually not a particular problem, but with `LoadSceneAsync`, it causes a different order of Start and continuation after await. So it is recommended not to use `LoadSceneAsync.ToUniTask`.
|
In UniTask, await directly uses native timing, while `WithCancellation` and `ToUniTask` use specified timing. This is usually not a particular problem, but with `LoadSceneAsync`, it causes a different order of Start and continuation after await. So it is recommended not to use `LoadSceneAsync.ToUniTask`.
|
||||||
|
|
||||||
In the stacktrace, you can check where it is running in playerloop.
|
In the stacktrace, you can check where it is running in playerloop.
|
||||||
|
|
||||||
@@ -669,7 +717,7 @@ Async LINQ is enabled when `using Cysharp.Threading.Tasks.Linq;`, and `UniTaskAs
|
|||||||
|
|
||||||
It's closer to UniRx (Reactive Extensions), but UniTaskAsyncEnumerable is a pull-based asynchronous stream, whereas Rx was a push-based asynchronous stream. Note that although similar, the characteristics are different and the details behave differently along with them.
|
It's closer to UniRx (Reactive Extensions), but UniTaskAsyncEnumerable is a pull-based asynchronous stream, whereas Rx was a push-based asynchronous stream. Note that although similar, the characteristics are different and the details behave differently along with them.
|
||||||
|
|
||||||
`UniTaskAsyncEnumerable` is the entry point like `Enumerbale`. In addition to the standard query operators, there are other generators for Unity such as `EveryUpdate`, `Timer`, `TimerFrame`, `Interval`, `IntervalFrame`, and `EveryValueChanged`. And also added additional UniTask original query operators like `Append`, `Prepend`, `DistinctUntilChanged`, `ToHashSet`, `Buffer`, `CombineLatest`, `Do`, `Never`, `ForEachAsync`, `Pairwise`, `Publish`, `Queue`, `Return`, `SkipUntil`, `TakeUntil`, `SkipUntilCanceled`, `TakeUntilCanceled`, `TakeLast`, `Subscribe`.
|
`UniTaskAsyncEnumerable` is the entry point like `Enumerable`. In addition to the standard query operators, there are other generators for Unity such as `EveryUpdate`, `Timer`, `TimerFrame`, `Interval`, `IntervalFrame`, and `EveryValueChanged`. And also added additional UniTask original query operators like `Append`, `Prepend`, `DistinctUntilChanged`, `ToHashSet`, `Buffer`, `CombineLatest`, `Do`, `Never`, `ForEachAsync`, `Pairwise`, `Publish`, `Queue`, `Return`, `SkipUntil`, `TakeUntil`, `SkipUntilCanceled`, `TakeUntilCanceled`, `TakeLast`, `Subscribe`.
|
||||||
|
|
||||||
The method with Func as an argument has three additional overloads, `***Await`, `***AwaitWithCancellation`.
|
The method with Func as an argument has three additional overloads, `***Await`, `***AwaitWithCancellation`.
|
||||||
|
|
||||||
@@ -757,32 +805,13 @@ async UniTask TripleClick(CancellationToken token)
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
All MonoBehaviour message events can convert async-streams by `AsyncTriggers` that can be enabled by `using Cysharp.Threading.Tasks.Triggers;`.
|
All MonoBehaviour message events can convert async-streams by `AsyncTriggers` that can be enabled by `using Cysharp.Threading.Tasks.Triggers;`. AsyncTrigger can be created using `GetAsync***Trigger` and triggers itself as UniTaskAsyncEnumerable.
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
using Cysharp.Threading.Tasks.Triggers;
|
var trigger = this.GetOnCollisionEnterAsyncHandler();
|
||||||
|
await trigger.OnCollisionEnterAsync();
|
||||||
async UniTaskVoid MonitorCollision()
|
await trigger.OnCollisionEnterAsync();
|
||||||
{
|
await trigger.OnCollisionEnterAsync();
|
||||||
await gameObject.OnCollisionEnterAsync();
|
|
||||||
Debug.Log("Collision Enter");
|
|
||||||
/* do anything */
|
|
||||||
|
|
||||||
await gameObject.OnCollisionExitAsync();
|
|
||||||
Debug.Log("Collision Exit");
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Similar to uGUI event, AsyncTrigger can be created using `GetAsync***Trigger` and triggers itself as UniTaskAsyncEnumerable.
|
|
||||||
|
|
||||||
```csharp
|
|
||||||
// use await multiple times, get AsyncTriggerHandler is more efficient.
|
|
||||||
using(var trigger = this.GetOnCollisionEnterAsyncHandler())
|
|
||||||
{
|
|
||||||
await OnCollisionEnterAsync();
|
|
||||||
await OnCollisionEnterAsync();
|
|
||||||
await OnCollisionEnterAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
// every moves.
|
// every moves.
|
||||||
await this.GetAsyncMoveTrigger().ForEachAsync(axisEventData =>
|
await this.GetAsyncMoveTrigger().ForEachAsync(axisEventData =>
|
||||||
@@ -810,9 +839,9 @@ rp.WithoutCurrent().BindTo(this.textComponent);
|
|||||||
|
|
||||||
await rp.WaitAsync(); // wait until next value set
|
await rp.WaitAsync(); // wait until next value set
|
||||||
|
|
||||||
// also exists ToReadOnlyReactiveProperty
|
// also exists ToReadOnlyAsyncReactiveProperty
|
||||||
var rp2 = new AsyncReactiveProperty<int>(99);
|
var rp2 = new AsyncReactiveProperty<int>(99);
|
||||||
var rorp = rp.CombineLatest(rp2, (x, y) => (x, y)).ToReadOnlyReactiveProperty();
|
var rorp = rp.CombineLatest(rp2, (x, y) => (x, y)).ToReadOnlyAsyncReactiveProperty(CancellationToken.None);
|
||||||
```
|
```
|
||||||
|
|
||||||
A pull-type asynchronous stream does not get the next values until the asynchronous processing in the sequence is complete. This could spill data from push-type events such as buttons.
|
A pull-type asynchronous stream does not get the next values until the asynchronous processing in the sequence is complete. This could spill data from push-type events such as buttons.
|
||||||
@@ -848,7 +877,7 @@ button.OnClickAsAsyncEnumerable().Subscribe(async x =>
|
|||||||
|
|
||||||
Channel
|
Channel
|
||||||
---
|
---
|
||||||
`Channel` is the same as [System.Threading.Tasks.Channels](https://docs.microsoft.com/ja-jp/dotnet/api/system.threading.channels?view=netcore-3.1) which is similar to a GoLang Channel.
|
`Channel` is the same as [System.Threading.Tasks.Channels](https://docs.microsoft.com/en-us/dotnet/api/system.threading.channels?view=netcore-3.1) which is similar to a GoLang Channel.
|
||||||
|
|
||||||
Currently it only supports multiple-producer, single-consumer unbounded channels. It can create by `Channel.CreateSingleConsumerUnbounded<T>()`.
|
Currently it only supports multiple-producer, single-consumer unbounded channels. It can create by `Channel.CreateSingleConsumerUnbounded<T>()`.
|
||||||
|
|
||||||
@@ -918,9 +947,9 @@ UniTask's own unit tests are written using Unity Test Runner and [Cysharp/Runtim
|
|||||||
|
|
||||||
ThreadPool limitation
|
ThreadPool limitation
|
||||||
---
|
---
|
||||||
Most UniTask methods run on a single thread (PlayerLoop), with only `UniTask.Run` and `UniTask.SwitchToThreadPool` running on a thread pool. If you use a thread pool, it won't work with WebGL and so on.
|
Most UniTask methods run on a single thread (PlayerLoop), with only `UniTask.Run`(`Task.Run` equivalent) and `UniTask.SwitchToThreadPool` running on a thread pool. If you use a thread pool, it won't work with WebGL and so on.
|
||||||
|
|
||||||
`UniTask.Run` will be deprecated in the future (marked with an Obsolete) and only `RunOnThreadPool` will be used. If you use `UniTask.Run`, consider whether you can use `UniTask.Create` or `UniTask.Void`.
|
`UniTask.Run` is now deprecated. You can use `UniTask.RunOnThreadPool` instead. And also consider whether you can use `UniTask.Create` or `UniTask.Void`.
|
||||||
|
|
||||||
IEnumerator.ToUniTask limitation
|
IEnumerator.ToUniTask limitation
|
||||||
---
|
---
|
||||||
@@ -937,7 +966,7 @@ UniTask can run on Unity Editor like an Editor Coroutine. However, there are som
|
|||||||
|
|
||||||
* UniTask.Delay's DelayType.DeltaTime, UnscaledDeltaTime do not work correctly because they can not get deltaTime in editor. Therefore run on EditMode, automatically change DelayType to `DelayType.Realtime` that wait for the right time.
|
* UniTask.Delay's DelayType.DeltaTime, UnscaledDeltaTime do not work correctly because they can not get deltaTime in editor. Therefore run on EditMode, automatically change DelayType to `DelayType.Realtime` that wait for the right time.
|
||||||
* All PlayerLoopTiming run on the timing `EditorApplication.update`.
|
* All PlayerLoopTiming run on the timing `EditorApplication.update`.
|
||||||
* `-batchmode` with `-quit` does not work because does not run `EditorApplication.update`(quit on single frame) so should not use `-quit` and quit manually with `Environment.Exit(0)`.
|
* `-batchmode` with `-quit` does not work because Unity does not run `EditorApplication.update` and quit after a single frame. Instead, don't use `-quit` and quit manually with `EditorApplication.Exit(0)`.
|
||||||
|
|
||||||
Compare with Standard Task API
|
Compare with Standard Task API
|
||||||
---
|
---
|
||||||
@@ -975,7 +1004,7 @@ Use UniTask type.
|
|||||||
| `IAsyncDisposable` | `IUniTaskAsyncDisposable` |
|
| `IAsyncDisposable` | `IUniTaskAsyncDisposable` |
|
||||||
| `Task.Delay` | `UniTask.Delay` |
|
| `Task.Delay` | `UniTask.Delay` |
|
||||||
| `Task.Yield` | `UniTask.Yield` |
|
| `Task.Yield` | `UniTask.Yield` |
|
||||||
| `Task.Run` | `UniTask.Run` |
|
| `Task.Run` | `UniTask.RunOnThreadPool` |
|
||||||
| `Task.WhenAll` | `UniTask.WhenAll` |
|
| `Task.WhenAll` | `UniTask.WhenAll` |
|
||||||
| `Task.WhenAny` | `UniTask.WhenAny` |
|
| `Task.WhenAny` | `UniTask.WhenAny` |
|
||||||
| `Task.CompletedTask` | `UniTask.CompletedTask` |
|
| `Task.CompletedTask` | `UniTask.CompletedTask` |
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 16
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 16.0.29613.14
|
VisualStudioVersion = 17.0.31606.5
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.NetCoreTests", "src\UniTask.NetCoreTests\UniTask.NetCoreTests.csproj", "{B3E311A4-70D8-4131-9965-C073A99D201A}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTask.NetCoreTests", "src\UniTask.NetCoreTests\UniTask.NetCoreTests.csproj", "{B3E311A4-70D8-4131-9965-C073A99D201A}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTask.NetCore", "src\UniTask.NetCore\UniTask.NetCore.csproj", "{16EE20D0-7FB1-483A-8467-A5EEDBF1F5BF}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTask.NetCore", "src\UniTask.NetCore\UniTask.NetCore.csproj", "{16EE20D0-7FB1-483A-8467-A5EEDBF1F5BF}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.NetCoreSandbox", "src\UniTask.NetCoreSandbox\UniTask.NetCoreSandbox.csproj", "{3915E72E-33E0-4A14-A6D8-872702200E58}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTask.NetCoreSandbox", "src\UniTask.NetCoreSandbox\UniTask.NetCoreSandbox.csproj", "{3915E72E-33E0-4A14-A6D8-872702200E58}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UniTask.Analyzer", "src\UniTask.Analyzer\UniTask.Analyzer.csproj", "{0AC6F052-A255-4EE3-9E05-1C02D49AB1C2}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -27,6 +29,10 @@ Global
|
|||||||
{3915E72E-33E0-4A14-A6D8-872702200E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{3915E72E-33E0-4A14-A6D8-872702200E58}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{3915E72E-33E0-4A14-A6D8-872702200E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{3915E72E-33E0-4A14-A6D8-872702200E58}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{3915E72E-33E0-4A14-A6D8-872702200E58}.Release|Any CPU.Build.0 = Release|Any CPU
|
{3915E72E-33E0-4A14-A6D8-872702200E58}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{0AC6F052-A255-4EE3-9E05-1C02D49AB1C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{0AC6F052-A255-4EE3-9E05-1C02D49AB1C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{0AC6F052-A255-4EE3-9E05-1C02D49AB1C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{0AC6F052-A255-4EE3-9E05-1C02D49AB1C2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
8
src/UniTask.Analyzer/Properties/launchSettings.json
Normal file
8
src/UniTask.Analyzer/Properties/launchSettings.json
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"UniTask.Analyzer": {
|
||||||
|
"commandName": "DebugRoslynComponent",
|
||||||
|
"targetProject": "..\\UniTask.NetCoreSandbox\\UniTask.NetCoreSandbox.csproj"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
29
src/UniTask.Analyzer/UniTask.Analyzer.csproj
Normal file
29
src/UniTask.Analyzer/UniTask.Analyzer.csproj
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>library</OutputType>
|
||||||
|
<TargetFramework>netstandard2.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsRoslynComponent>true</IsRoslynComponent>
|
||||||
|
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackBuildOutputs</TargetsForTfmSpecificContentInPackage>
|
||||||
|
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||||
|
<IncludeSymbols>false</IncludeSymbols>
|
||||||
|
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
|
||||||
|
<DevelopmentDependency>true</DevelopmentDependency>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.2">
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<Target Name="PackBuildOutputs" DependsOnTargets="SatelliteDllsProjectOutputGroup;DebugSymbolsProjectOutputGroup">
|
||||||
|
<ItemGroup>
|
||||||
|
<TfmSpecificPackageFile Include="$(TargetDir)\*.dll" PackagePath="analyzers\dotnet\cs" />
|
||||||
|
<TfmSpecificPackageFile Include="@(SatelliteDllsProjectOutputGroupOutput->'%(FinalOutputPath)')" PackagePath="analyzers\dotnet\cs\%(SatelliteDllsProjectOutputGroupOutput.Culture)\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Target>
|
||||||
|
</Project>
|
||||||
54
src/UniTask.Analyzer/UniTaskAnalyzer.cs
Normal file
54
src/UniTask.Analyzer/UniTaskAnalyzer.cs
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#pragma warning disable RS2008
|
||||||
|
|
||||||
|
using Microsoft.CodeAnalysis;
|
||||||
|
using Microsoft.CodeAnalysis.Diagnostics;
|
||||||
|
using Microsoft.CodeAnalysis.Operations;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Threading;
|
||||||
|
|
||||||
|
namespace UniTask.Analyzer
|
||||||
|
{
|
||||||
|
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||||
|
public class UniTaskAnalyzer : DiagnosticAnalyzer
|
||||||
|
{
|
||||||
|
private static readonly DiagnosticDescriptor Rule = new DiagnosticDescriptor(
|
||||||
|
id: "UNITASK001",
|
||||||
|
title: "UniTaskAnalyzer001: Must pass CancellationToken",
|
||||||
|
messageFormat: "Must pass CancellationToken",
|
||||||
|
category: "Usage",
|
||||||
|
defaultSeverity: DiagnosticSeverity.Error,
|
||||||
|
isEnabledByDefault: true,
|
||||||
|
description: "Pass CancellationToken or CancellationToken.None.");
|
||||||
|
|
||||||
|
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { return ImmutableArray.Create(Rule); } }
|
||||||
|
|
||||||
|
public override void Initialize(AnalysisContext context)
|
||||||
|
{
|
||||||
|
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
|
||||||
|
context.EnableConcurrentExecution();
|
||||||
|
|
||||||
|
context.RegisterOperationAction(AnalyzeOperation, OperationKind.Invocation);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AnalyzeOperation(OperationAnalysisContext context)
|
||||||
|
{
|
||||||
|
var token = context.Compilation.GetTypeByMetadataName(typeof(CancellationToken).FullName);
|
||||||
|
if (token == null) return;
|
||||||
|
|
||||||
|
if (context.Operation is IInvocationOperation invocation)
|
||||||
|
{
|
||||||
|
foreach (var arg in invocation.Arguments)
|
||||||
|
{
|
||||||
|
if (arg.ArgumentKind == ArgumentKind.DefaultValue)
|
||||||
|
{
|
||||||
|
if (SymbolEqualityComparer.Default.Equals(arg.Parameter.Type, token))
|
||||||
|
{
|
||||||
|
var diagnostic = Diagnostic.Create(Rule, arg.Syntax.GetLocation());
|
||||||
|
context.ReportDiagnostic(diagnostic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,8 @@
|
|||||||
<AssemblyName>UniTask</AssemblyName>
|
<AssemblyName>UniTask</AssemblyName>
|
||||||
<LangVersion>8.0</LangVersion>
|
<LangVersion>8.0</LangVersion>
|
||||||
<RootNamespace>Cysharp.Threading.Tasks</RootNamespace>
|
<RootNamespace>Cysharp.Threading.Tasks</RootNamespace>
|
||||||
|
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||||
|
<NoWarn>$(NoWarn);CS1591</NoWarn>
|
||||||
|
|
||||||
<!-- NuGet Packaging -->
|
<!-- NuGet Packaging -->
|
||||||
<Id>UniTask</Id>
|
<Id>UniTask</Id>
|
||||||
@@ -19,6 +21,9 @@
|
|||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<PackageIcon>Icon.png</PackageIcon>
|
<PackageIcon>Icon.png</PackageIcon>
|
||||||
|
<SignAssembly>true</SignAssembly>
|
||||||
|
<AssemblyOriginatorKeyFile>opensource.snk</AssemblyOriginatorKeyFile>
|
||||||
|
<IsPackable>true</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -26,30 +31,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="..\UniTask\Assets\Plugins\UniTask\Runtime\**\*.cs"
|
<Compile Include="..\UniTask\Assets\Plugins\UniTask\Runtime\**\*.cs" Exclude="
..\UniTask\Assets\Plugins\UniTask\Editor\*.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Triggers\*.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Linq\UnityExtensions\*.cs;
 
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityEqualityComparer.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\DiagnosticsExtensions.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\PlayerLoopRunner.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\ContinuationQueue.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityWebRequestExtensions.cs;
 
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTaskSynchronizationContext.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\CancellationTokenSourceExtensions.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\TimeoutController.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopHelper.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopTimer.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Delay.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Run.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Bridge.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.WaitUntil.cs;
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.*;
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityBindingExtensions.cs;
" />
|
||||||
Exclude="
|
<Compile Remove="..\UniTask\Assets\Plugins\UniTask\Runtime\_InternalVisibleTo.cs" />
|
||||||
..\UniTask\Assets\Plugins\UniTask\Editor\*.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Triggers\*.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Linq\UnityExtensions\*.cs;
|
|
||||||
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityEqualityComparer.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\DiagnosticsExtensions.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\PlayerLoopRunner.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\ContinuationQueue.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityWebRequestExtensions.cs;
|
|
||||||
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTaskSynchronizationContext.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\CancellationTokenSourceExtensions.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\TimeoutController.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopHelper.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Delay.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Run.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Bridge.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.WaitUntil.cs;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.*;
|
|
||||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityBindingExtensions.cs;
|
|
||||||
" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
BIN
src/UniTask.NetCore/opensource.snk
Normal file
BIN
src/UniTask.NetCore/opensource.snk
Normal file
Binary file not shown.
@@ -1,258 +0,0 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
|
||||||
using System.Linq;
|
|
||||||
using BenchmarkDotNet.Configs;
|
|
||||||
using BenchmarkDotNet.Diagnosers;
|
|
||||||
using BenchmarkDotNet.Exporters;
|
|
||||||
using BenchmarkDotNet.Jobs;
|
|
||||||
using BenchmarkDotNet.Running;
|
|
||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using PooledAwait;
|
|
||||||
using System;
|
|
||||||
using System.Runtime.ExceptionServices;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using Cysharp.Threading.Tasks.CompilerServices;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
|
|
||||||
[Config(typeof(BenchmarkConfig))]
|
|
||||||
public class AllocationCheck
|
|
||||||
{
|
|
||||||
// note: all the benchmarks use Task/Task<T> for the public API, because BenchmarkDotNet
|
|
||||||
// doesn't work reliably with more exotic task-types (even just ValueTask fails); instead,
|
|
||||||
// we'll obscure the cost of the outer awaitable by doing a relatively large number of
|
|
||||||
// iterations, so that we're only really measuring the inner loop
|
|
||||||
private const int InnerOps = 1000;
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps)]
|
|
||||||
public async Task ViaUniTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
{
|
|
||||||
var a = Core();
|
|
||||||
var b = Core();
|
|
||||||
var c = Core();
|
|
||||||
await a;
|
|
||||||
await b;
|
|
||||||
await c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static async UniTask Core()
|
|
||||||
{
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps)]
|
|
||||||
public async Task<int> ViaUniTaskT()
|
|
||||||
{
|
|
||||||
var sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
{
|
|
||||||
var a = Core();
|
|
||||||
var b = Core();
|
|
||||||
var c = Core();
|
|
||||||
sum += await a;
|
|
||||||
sum += await b;
|
|
||||||
sum += await c;
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async UniTask<int> Core()
|
|
||||||
{
|
|
||||||
var a = await new TestAwaiter<int>(false, UniTaskStatus.Succeeded, 10);
|
|
||||||
var b = await new TestAwaiter<int>(false, UniTaskStatus.Succeeded, 10);
|
|
||||||
var c = await new TestAwaiter<int>(false, UniTaskStatus.Succeeded, 10);
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//[Benchmark(OperationsPerInvoke = InnerOps)]
|
|
||||||
//[Benchmark]
|
|
||||||
public void ViaUniTaskVoid()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
{
|
|
||||||
Core().Forget();
|
|
||||||
Core().Forget();
|
|
||||||
Core().Forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
static async UniTaskVoid Core()
|
|
||||||
{
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Foo : IAsyncStateMachine
|
|
||||||
{
|
|
||||||
public AsyncUniTaskVoidMethodBuilder builder;
|
|
||||||
public TestAwaiter awaiter;
|
|
||||||
public TestAwaiter awaiterawaiter;
|
|
||||||
|
|
||||||
public int state;
|
|
||||||
|
|
||||||
public void MoveNext()
|
|
||||||
{
|
|
||||||
switch (state)
|
|
||||||
{
|
|
||||||
case -1:
|
|
||||||
awaiterawaiter = awaiter.GetAwaiter();
|
|
||||||
if (awaiterawaiter.IsCompleted)
|
|
||||||
{
|
|
||||||
goto case 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
state = 0;
|
|
||||||
builder.AwaitUnsafeOnCompleted(ref awaiterawaiter, ref this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
default:
|
|
||||||
goto END;
|
|
||||||
}
|
|
||||||
|
|
||||||
END:
|
|
||||||
builder.SetResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetStateMachine(IAsyncStateMachine stateMachine)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TaskTestException : Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct TestAwaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
readonly UniTaskStatus status;
|
|
||||||
readonly bool isCompleted;
|
|
||||||
|
|
||||||
public TestAwaiter(bool isCompleted, UniTaskStatus status)
|
|
||||||
{
|
|
||||||
this.isCompleted = isCompleted;
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestAwaiter GetAwaiter() => this;
|
|
||||||
|
|
||||||
public bool IsCompleted => isCompleted;
|
|
||||||
|
|
||||||
public void GetResult()
|
|
||||||
{
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case UniTaskStatus.Faulted:
|
|
||||||
throw new TaskTestException();
|
|
||||||
case UniTaskStatus.Canceled:
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
case UniTaskStatus.Pending:
|
|
||||||
case UniTaskStatus.Succeeded:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(ThreadPoolWorkItem.Create(continuation), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(ThreadPoolWorkItem.Create(continuation), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct TestAwaiter<T> : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
readonly UniTaskStatus status;
|
|
||||||
readonly bool isCompleted;
|
|
||||||
readonly T value;
|
|
||||||
|
|
||||||
public TestAwaiter(bool isCompleted, UniTaskStatus status, T value)
|
|
||||||
{
|
|
||||||
this.isCompleted = isCompleted;
|
|
||||||
this.status = status;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestAwaiter<T> GetAwaiter() => this;
|
|
||||||
|
|
||||||
public bool IsCompleted => isCompleted;
|
|
||||||
|
|
||||||
public T GetResult()
|
|
||||||
{
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case UniTaskStatus.Faulted:
|
|
||||||
throw new TaskTestException();
|
|
||||||
case UniTaskStatus.Canceled:
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
case UniTaskStatus.Pending:
|
|
||||||
case UniTaskStatus.Succeeded:
|
|
||||||
default:
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(ThreadPoolWorkItem.Create(continuation), false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(ThreadPoolWorkItem.Create(continuation), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class ThreadPoolWorkItem : IThreadPoolWorkItem
|
|
||||||
{
|
|
||||||
public static readonly ConcurrentQueue<ThreadPoolWorkItem> pool = new ConcurrentQueue<ThreadPoolWorkItem>();
|
|
||||||
|
|
||||||
public static void CreatePoolItems(int count)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
pool.Enqueue(new ThreadPoolWorkItem());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Action continuation;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public static ThreadPoolWorkItem Create(Action continuation)
|
|
||||||
{
|
|
||||||
if (!pool.TryDequeue(out var item))
|
|
||||||
{
|
|
||||||
item = new ThreadPoolWorkItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
item.continuation = continuation;
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public void Execute()
|
|
||||||
{
|
|
||||||
var call = continuation;
|
|
||||||
continuation = null;
|
|
||||||
pool.Enqueue(this);
|
|
||||||
|
|
||||||
call.Invoke();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,283 +0,0 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
|
||||||
using System.Linq;
|
|
||||||
using BenchmarkDotNet.Configs;
|
|
||||||
using BenchmarkDotNet.Diagnosers;
|
|
||||||
using BenchmarkDotNet.Exporters;
|
|
||||||
using BenchmarkDotNet.Jobs;
|
|
||||||
using BenchmarkDotNet.Running;
|
|
||||||
using Cysharp.Threading.Tasks;
|
|
||||||
using PooledAwait;
|
|
||||||
using System;
|
|
||||||
using System.Runtime.ExceptionServices;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using Cysharp.Threading.Tasks.CompilerServices;
|
|
||||||
|
|
||||||
//class Program
|
|
||||||
//{
|
|
||||||
// static void Main(string[] args)
|
|
||||||
// {
|
|
||||||
// var switcher = new BenchmarkSwitcher(new[]
|
|
||||||
// {
|
|
||||||
// typeof(StandardBenchmark)
|
|
||||||
// });
|
|
||||||
|
|
||||||
//#if DEBUG
|
|
||||||
// var b = new StandardBenchmark();
|
|
||||||
|
|
||||||
//#else
|
|
||||||
// switcher.Run(args);
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
public class BenchmarkConfig : ManualConfig
|
|
||||||
{
|
|
||||||
public BenchmarkConfig()
|
|
||||||
{
|
|
||||||
AddDiagnoser(MemoryDiagnoser.Default);
|
|
||||||
AddJob(Job.ShortRun.WithLaunchCount(1).WithIterationCount(1).WithWarmupCount(1)/*.RunOncePerIteration()*/);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// borrowed from PooledAwait
|
|
||||||
|
|
||||||
[Config(typeof(BenchmarkConfig))]
|
|
||||||
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
|
|
||||||
[CategoriesColumn]
|
|
||||||
public class ComparisonBenchmarks
|
|
||||||
{
|
|
||||||
// note: all the benchmarks use Task/Task<T> for the public API, because BenchmarkDotNet
|
|
||||||
// doesn't work reliably with more exotic task-types (even just ValueTask fails); instead,
|
|
||||||
// we'll obscure the cost of the outer awaitable by doing a relatively large number of
|
|
||||||
// iterations, so that we're only really measuring the inner loop
|
|
||||||
private const int InnerOps = 1000;
|
|
||||||
|
|
||||||
public bool ConfigureAwait { get; set; } = false;
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = ".NET")]
|
|
||||||
[BenchmarkCategory("Task<T>")]
|
|
||||||
public async Task<int> ViaTaskT()
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
sum += await Inner(1, 2).ConfigureAwait(ConfigureAwait);
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async Task<int> Inner(int x, int y)
|
|
||||||
{
|
|
||||||
int i = x;
|
|
||||||
await Task.Yield();
|
|
||||||
i *= y;
|
|
||||||
await Task.Yield();
|
|
||||||
return 5 * i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = ".NET")]
|
|
||||||
[BenchmarkCategory("Task")]
|
|
||||||
public async Task ViaTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
await Inner().ConfigureAwait(ConfigureAwait);
|
|
||||||
|
|
||||||
static async Task Inner()
|
|
||||||
{
|
|
||||||
await Task.Yield();
|
|
||||||
await Task.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = ".NET")]
|
|
||||||
[BenchmarkCategory("ValueTask<T>")]
|
|
||||||
public async Task<int> ViaValueTaskT()
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
sum += await Inner(1, 2).ConfigureAwait(ConfigureAwait);
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async ValueTask<int> Inner(int x, int y)
|
|
||||||
{
|
|
||||||
int i = x;
|
|
||||||
await Task.Yield();
|
|
||||||
i *= y;
|
|
||||||
await Task.Yield();
|
|
||||||
return 5 * i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = ".NET")]
|
|
||||||
[BenchmarkCategory("ValueTask")]
|
|
||||||
public async Task ViaValueTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
await Inner().ConfigureAwait(ConfigureAwait);
|
|
||||||
|
|
||||||
static async ValueTask Inner()
|
|
||||||
{
|
|
||||||
await Task.Yield();
|
|
||||||
await Task.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "Pooled")]
|
|
||||||
[BenchmarkCategory("ValueTask<T>")]
|
|
||||||
public async Task<int> ViaPooledValueTaskT()
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
sum += await Inner(1, 2).ConfigureAwait(ConfigureAwait);
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async PooledValueTask<int> Inner(int x, int y)
|
|
||||||
{
|
|
||||||
int i = x;
|
|
||||||
await Task.Yield();
|
|
||||||
i *= y;
|
|
||||||
await Task.Yield();
|
|
||||||
return 5 * i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "Pooled")]
|
|
||||||
[BenchmarkCategory("ValueTask")]
|
|
||||||
public async Task ViaPooledValueTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
await Inner().ConfigureAwait(ConfigureAwait);
|
|
||||||
|
|
||||||
static async PooledValueTask Inner()
|
|
||||||
{
|
|
||||||
await Task.Yield();
|
|
||||||
await Task.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "Pooled")]
|
|
||||||
[BenchmarkCategory("Task<T>")]
|
|
||||||
public async Task<int> ViaPooledTaskT()
|
|
||||||
{
|
|
||||||
int sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
sum += await Inner(1, 2).ConfigureAwait(ConfigureAwait);
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async PooledTask<int> Inner(int x, int y)
|
|
||||||
{
|
|
||||||
int i = x;
|
|
||||||
await Task.Yield();
|
|
||||||
i *= y;
|
|
||||||
await Task.Yield();
|
|
||||||
return 5 * i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "Pooled")]
|
|
||||||
[BenchmarkCategory("Task")]
|
|
||||||
public async Task ViaPooledTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
await Inner().ConfigureAwait(ConfigureAwait);
|
|
||||||
|
|
||||||
static async PooledTask Inner()
|
|
||||||
{
|
|
||||||
await Task.Yield();
|
|
||||||
await Task.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---
|
|
||||||
|
|
||||||
//[Benchmark(OperationsPerInvoke = InnerOps, Description = "UniTaskVoid")]
|
|
||||||
//[BenchmarkCategory("UniTask")]
|
|
||||||
//public async Task ViaUniTaskVoid()
|
|
||||||
//{
|
|
||||||
// for (int i = 0; i < InnerOps; i++)
|
|
||||||
// {
|
|
||||||
// await Inner();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static async UniTaskVoid Inner()
|
|
||||||
// {
|
|
||||||
// await UniTask.Yield();
|
|
||||||
// await UniTask.Yield();
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "UniTask")]
|
|
||||||
[BenchmarkCategory("UniTask")]
|
|
||||||
public async Task ViaUniTask()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
{
|
|
||||||
await Inner();
|
|
||||||
}
|
|
||||||
|
|
||||||
static async UniTask Inner()
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark(OperationsPerInvoke = InnerOps, Description = "UniTaskT")]
|
|
||||||
[BenchmarkCategory("UniTask")]
|
|
||||||
public async Task<int> ViaUniTaskT()
|
|
||||||
{
|
|
||||||
var sum = 0;
|
|
||||||
for (int i = 0; i < InnerOps; i++)
|
|
||||||
{
|
|
||||||
sum += await Inner(1, 2);
|
|
||||||
}
|
|
||||||
return sum;
|
|
||||||
|
|
||||||
static async UniTask<int> Inner(int x, int y)
|
|
||||||
{
|
|
||||||
int i = x;
|
|
||||||
await UniTask.Yield();
|
|
||||||
i *= y;
|
|
||||||
await UniTask.Yield();
|
|
||||||
return 5 * i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyAwaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
public MyAwaiter GetAwaiter() => this;
|
|
||||||
|
|
||||||
public bool IsCompleted => false;
|
|
||||||
|
|
||||||
public void GetResult()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
continuation();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
continuation();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct MyTestStateMachine : IAsyncStateMachine
|
|
||||||
{
|
|
||||||
public void MoveNext()
|
|
||||||
{
|
|
||||||
//throw new NotImplementedException();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void SetStateMachine(IAsyncStateMachine stateMachine)
|
|
||||||
{
|
|
||||||
//throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,499 +17,34 @@ using System.Reactive.Concurrency;
|
|||||||
|
|
||||||
namespace NetCoreSandbox
|
namespace NetCoreSandbox
|
||||||
{
|
{
|
||||||
public class MySyncContext : SynchronizationContext
|
public class Program
|
||||||
{
|
{
|
||||||
public MySyncContext()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Post(SendOrPostCallback d, object state)
|
|
||||||
{
|
|
||||||
Console.WriteLine("Called SyncContext Post!");
|
|
||||||
base.Post(d, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Text
|
|
||||||
{
|
|
||||||
|
|
||||||
public string text { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ZeroAllocAsyncAwaitInDotNetCore
|
|
||||||
{
|
|
||||||
public ValueTask<int> NanikaAsync(int x, int y)
|
|
||||||
{
|
|
||||||
return Core(this, x, y);
|
|
||||||
|
|
||||||
static async UniTask<int> Core(ZeroAllocAsyncAwaitInDotNetCore self, int x, int y)
|
|
||||||
{
|
|
||||||
// nanika suru...
|
|
||||||
await Task.Delay(TimeSpan.FromSeconds(x + y));
|
|
||||||
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public class TaskTestException : Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class Foo
|
|
||||||
{
|
|
||||||
public async UniTask MethodFooAsync()
|
|
||||||
{
|
|
||||||
await MethodBarAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
private async UniTask MethodBarAsync()
|
|
||||||
|
|
||||||
{
|
|
||||||
Throw();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Throw()
|
|
||||||
{
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct TestAwaiter : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
readonly UniTaskStatus status;
|
|
||||||
readonly bool isCompleted;
|
|
||||||
|
|
||||||
public TestAwaiter(bool isCompleted, UniTaskStatus status)
|
|
||||||
{
|
|
||||||
this.isCompleted = isCompleted;
|
|
||||||
this.status = status;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestAwaiter GetAwaiter() => this;
|
|
||||||
|
|
||||||
public bool IsCompleted => isCompleted;
|
|
||||||
|
|
||||||
public void GetResult()
|
|
||||||
{
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case UniTaskStatus.Faulted:
|
|
||||||
throw new TaskTestException();
|
|
||||||
case UniTaskStatus.Canceled:
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
case UniTaskStatus.Pending:
|
|
||||||
case UniTaskStatus.Succeeded:
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.QueueUserWorkItem(_ => continuation(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public struct TestAwaiter<T> : ICriticalNotifyCompletion
|
|
||||||
{
|
|
||||||
readonly UniTaskStatus status;
|
|
||||||
readonly bool isCompleted;
|
|
||||||
readonly T value;
|
|
||||||
|
|
||||||
public TestAwaiter(bool isCompleted, UniTaskStatus status, T value)
|
|
||||||
{
|
|
||||||
this.isCompleted = isCompleted;
|
|
||||||
this.status = status;
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestAwaiter<T> GetAwaiter() => this;
|
|
||||||
|
|
||||||
public bool IsCompleted => isCompleted;
|
|
||||||
|
|
||||||
public T GetResult()
|
|
||||||
{
|
|
||||||
switch (status)
|
|
||||||
{
|
|
||||||
case UniTaskStatus.Faulted:
|
|
||||||
throw new TaskTestException();
|
|
||||||
case UniTaskStatus.Canceled:
|
|
||||||
throw new OperationCanceledException();
|
|
||||||
case UniTaskStatus.Pending:
|
|
||||||
case UniTaskStatus.Succeeded:
|
|
||||||
default:
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void OnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.QueueUserWorkItem(_ => continuation(), null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UnsafeOnCompleted(Action continuation)
|
|
||||||
{
|
|
||||||
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static partial class UnityUIComponentExtensions
|
|
||||||
{
|
|
||||||
public static void BindTo(this IUniTaskAsyncEnumerable<string> source, Text text)
|
|
||||||
{
|
|
||||||
AAAACORECORE(source, text).Forget();
|
|
||||||
|
|
||||||
async UniTaskVoid AAAACORECORE(IUniTaskAsyncEnumerable<string> source2, Text text2)
|
|
||||||
{
|
|
||||||
var e = source2.GetAsyncEnumerator();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
while (await e.MoveNextAsync())
|
|
||||||
{
|
|
||||||
text2.text = e.Current;
|
|
||||||
// action(e.Current);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (e != null)
|
|
||||||
{
|
|
||||||
await e.DisposeAsync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//public static IDisposable SubscribeToText<T>(this IObservable<T> source, Text text)
|
|
||||||
//{
|
|
||||||
// return source.SubscribeWithState(text, (x, t) => t.text = x.ToString());
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static IDisposable SubscribeToText<T>(this IObservable<T> source, Text text, Func<T, string> selector)
|
|
||||||
//{
|
|
||||||
// return source.SubscribeWithState2(text, selector, (x, t, s) => t.text = s(x));
|
|
||||||
//}
|
|
||||||
|
|
||||||
//public static IDisposable SubscribeToInteractable(this IObservable<bool> source, Selectable selectable)
|
|
||||||
//{
|
|
||||||
// return source.SubscribeWithState(selectable, (x, s) => s.interactable = x);
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Program
|
|
||||||
{
|
|
||||||
static string FlattenGenArgs(Type type)
|
|
||||||
{
|
|
||||||
if (type.IsGenericType)
|
|
||||||
{
|
|
||||||
var t = string.Join(", ", type.GetGenericArguments().Select(x => FlattenGenArgs(x)));
|
|
||||||
return Regex.Replace(type.Name, "`.+", "") + "<" + t + ">";
|
|
||||||
}
|
|
||||||
//x.ReturnType.GetGenericArguments()
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return type.Name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static async IAsyncEnumerable<int> FooAsync([EnumeratorCancellation]CancellationToken cancellationToken = default)
|
|
||||||
{
|
|
||||||
yield return 1;
|
|
||||||
await Task.Delay(10, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class MyDisposable : IDisposable
|
|
||||||
{
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void Test()
|
|
||||||
{
|
|
||||||
var disp = new MyDisposable();
|
|
||||||
|
|
||||||
using var _ = new MyDisposable();
|
|
||||||
|
|
||||||
Console.WriteLine("tako");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static async UniTask FooBarAsync()
|
|
||||||
{
|
|
||||||
await using (UniTask.ReturnToCurrentSynchronizationContext())
|
|
||||||
{
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static async UniTask Aaa()
|
|
||||||
{
|
|
||||||
await FooBarAsync();
|
|
||||||
|
|
||||||
Console.WriteLine("FooBarAsync End");
|
|
||||||
}
|
|
||||||
|
|
||||||
static async UniTask WhereSelect()
|
|
||||||
{
|
|
||||||
await foreach (var item in UniTaskAsyncEnumerable.Range(1, 10)
|
|
||||||
.SelectAwait(async x =>
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
return x;
|
|
||||||
})
|
|
||||||
.Where(x => x % 2 == 0))
|
|
||||||
{
|
|
||||||
Console.WriteLine(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static async Task Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
#if !DEBUG
|
var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
|
||||||
|
// OK.
|
||||||
|
await FooAsync(10, cts.Token);
|
||||||
|
|
||||||
|
// NG(Compiler Error)
|
||||||
|
// await FooAsync(10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//await new AllocationCheck().ViaUniTaskVoid();
|
|
||||||
//Console.ReadLine();
|
|
||||||
BenchmarkDotNet.Running.BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);
|
|
||||||
|
|
||||||
//await new ComparisonBenchmarks().ViaUniTaskT();
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
var e = UniTaskAsyncEnumerable.Create<int>(async (writer, token) =>
|
|
||||||
{
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Start {i}");
|
|
||||||
await writer.YieldAsync(i);
|
|
||||||
Console.WriteLine($"End {i}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var ee = e.GetAsyncEnumerator();
|
|
||||||
while (await ee.MoveNextAsync())
|
|
||||||
{
|
|
||||||
Console.WriteLine("ForEach " + ee.Current);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async UniTask YieldCore()
|
static async UniTask FooAsync(int x, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS1998
|
|
||||||
|
|
||||||
|
|
||||||
static async UniTask<int> AsyncTest()
|
|
||||||
{
|
|
||||||
// empty
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(true, UniTaskStatus.Succeeded);
|
|
||||||
await new TestAwaiter(false, UniTaskStatus.Succeeded);
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#pragma warning restore CS1998
|
|
||||||
|
|
||||||
void Foo()
|
|
||||||
{
|
|
||||||
|
|
||||||
// AsyncEnumerable.Range(1,10).Do(
|
|
||||||
|
|
||||||
// AsyncEnumerable.t
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
sb.AppendLine(@"using System;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
namespace Cysharp.Threading.Tasks.Linq
|
|
||||||
{
|
|
||||||
");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var chako = typeof(AsyncEnumerable).GetMethods()
|
|
||||||
.OrderBy(x => x.Name)
|
|
||||||
.Select(x =>
|
|
||||||
{
|
|
||||||
var ret = FlattenGenArgs(x.ReturnType);
|
|
||||||
|
|
||||||
|
|
||||||
var generics = string.Join(", ", x.GetGenericArguments().Select(x => x.Name));
|
|
||||||
|
|
||||||
if (x.GetParameters().Length == 0) return "";
|
|
||||||
|
|
||||||
var self = x.GetParameters().First();
|
|
||||||
if (x.GetCustomAttributes(typeof(ExtensionAttribute), true).Length == 0)
|
|
||||||
{
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
var arg1Type = FlattenGenArgs(x.GetParameters().First().ParameterType);
|
|
||||||
|
|
||||||
var others = string.Join(", ", x.GetParameters().Skip(1).Select(y => FlattenGenArgs(y.ParameterType) + " " + y.Name));
|
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(others))
|
|
||||||
{
|
|
||||||
others = ", " + others;
|
|
||||||
}
|
|
||||||
|
|
||||||
var template = $"public static {ret} {x.Name}<{generics}>(this {arg1Type} {self.Name}{others})";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return template.Replace("ValueTask", "UniTask").Replace("IAsyncEnumerable", "IUniTaskAsyncEnumerable").Replace("<>", "");
|
|
||||||
})
|
|
||||||
.Where(x => x != "")
|
|
||||||
.Select(x => x + "\r\n{\r\n throw new NotImplementedException();\r\n}")
|
|
||||||
.ToArray();
|
|
||||||
|
|
||||||
var huga = string.Join("\r\n\r\n", chako);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach (var item in typeof(AsyncEnumerable).GetMethods().Select(x => x.Name).Distinct())
|
|
||||||
{
|
|
||||||
if (item.EndsWith("AwaitAsync") || item.EndsWith("AwaitWithCancellationAsync") || item.EndsWith("WithCancellation"))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var item2 = item.Replace("Async", "");
|
|
||||||
item2 = item2.Replace("Await", "");
|
|
||||||
|
|
||||||
var format = @"
|
|
||||||
internal sealed class {0}
|
|
||||||
{{
|
|
||||||
}}
|
|
||||||
";
|
|
||||||
|
|
||||||
sb.Append(string.Format(format, item2));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Append("}");
|
|
||||||
|
|
||||||
|
|
||||||
Console.WriteLine(sb.ToString());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static async IAsyncEnumerable<int> AsyncGen()
|
|
||||||
{
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
yield return 10;
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
yield return 100;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyEnumerable : IEnumerable<int>
|
|
||||||
{
|
|
||||||
public IEnumerator<int> GetEnumerator()
|
|
||||||
{
|
|
||||||
return new MyEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyEnumerator : IEnumerator<int>
|
|
||||||
{
|
|
||||||
public int Current => throw new NotImplementedException();
|
|
||||||
|
|
||||||
object IEnumerator.Current => throw new NotImplementedException();
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Console.WriteLine("Called Dispose");
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool MoveNext()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Reset()
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class MyClass<T>
|
|
||||||
{
|
|
||||||
public CustomAsyncEnumerator<T> GetAsyncEnumerator()
|
|
||||||
{
|
|
||||||
//IAsyncEnumerable
|
|
||||||
return new CustomAsyncEnumerator<T>();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public struct CustomAsyncEnumerator<T>
|
|
||||||
{
|
|
||||||
int count;
|
|
||||||
|
|
||||||
public T Current
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniTask<bool> MoveNextAsync()
|
|
||||||
{
|
|
||||||
if (count++ == 3)
|
|
||||||
{
|
|
||||||
return UniTask.FromResult(false);
|
|
||||||
//return false;
|
|
||||||
}
|
|
||||||
return UniTask.FromResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public UniTask DisposeAsync()
|
|
||||||
{
|
|
||||||
return default;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,473 +0,0 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Threading;
|
|
||||||
|
|
||||||
[Config(typeof(BenchmarkConfig))]
|
|
||||||
public class QueueCheck
|
|
||||||
{
|
|
||||||
Node node1 = new Node();
|
|
||||||
Node node2 = new Node();
|
|
||||||
RefNode refNode1 = new RefNode();
|
|
||||||
RefNode refNode2 = new RefNode();
|
|
||||||
Queue<Node> q1 = new Queue<Node>();
|
|
||||||
Stack<Node> s1 = new Stack<Node>();
|
|
||||||
ConcurrentQueue<Node> cq = new ConcurrentQueue<Node>();
|
|
||||||
ConcurrentStack<Node> cs = new ConcurrentStack<Node>();
|
|
||||||
static TaskPool<Node> pool;
|
|
||||||
static TaskPoolRefNode<RefNode> poolRefNode;
|
|
||||||
static TaskPoolEqualNull<Node> poolEqualNull;
|
|
||||||
static TaskPoolClass<Node> poolClass = new TaskPoolClass<Node>();
|
|
||||||
static TaskPoolWithoutSize<Node> poolWithoutSize;
|
|
||||||
static TaskPoolWithoutLock<Node> poolWithoutLock;
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void Queue()
|
|
||||||
{
|
|
||||||
q1.Enqueue(node1);
|
|
||||||
q1.Enqueue(node1);
|
|
||||||
q1.TryDequeue(out _);
|
|
||||||
q1.TryDequeue(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void QueueLock()
|
|
||||||
{
|
|
||||||
lock (q1) { q1.Enqueue(node1); }
|
|
||||||
lock (q1) { q1.Enqueue(node1); }
|
|
||||||
lock (q1) { q1.TryDequeue(out _); }
|
|
||||||
lock (q1) { q1.TryDequeue(out _); }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void Stack()
|
|
||||||
{
|
|
||||||
s1.Push(node1);
|
|
||||||
s1.Push(node2);
|
|
||||||
s1.TryPop(out _);
|
|
||||||
s1.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void StackLock()
|
|
||||||
{
|
|
||||||
lock (s1) { s1.Push(node1); }
|
|
||||||
lock (s1) { s1.Push(node2); }
|
|
||||||
lock (s1) { s1.TryPop(out _); }
|
|
||||||
lock (s1) { s1.TryPop(out _); }
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void ConcurrentQueue()
|
|
||||||
{
|
|
||||||
cq.Enqueue(node1);
|
|
||||||
cq.Enqueue(node1);
|
|
||||||
cq.TryDequeue(out _);
|
|
||||||
cq.TryDequeue(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void ConcurrentStack()
|
|
||||||
{
|
|
||||||
cs.Push(node1);
|
|
||||||
cs.Push(node2);
|
|
||||||
cs.TryPop(out _);
|
|
||||||
cs.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPool()
|
|
||||||
{
|
|
||||||
pool.TryPush(node1);
|
|
||||||
pool.TryPush(node2);
|
|
||||||
pool.TryPop(out _);
|
|
||||||
pool.TryPop(out _);
|
|
||||||
}
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPoolRefNode()
|
|
||||||
{
|
|
||||||
poolRefNode.TryPush(refNode1);
|
|
||||||
poolRefNode.TryPush(refNode2);
|
|
||||||
poolRefNode.TryPop(out _);
|
|
||||||
poolRefNode.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPoolEqualNull()
|
|
||||||
{
|
|
||||||
poolEqualNull.TryPush(node1);
|
|
||||||
poolEqualNull.TryPush(node2);
|
|
||||||
poolEqualNull.TryPop(out _);
|
|
||||||
poolEqualNull.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPoolClass()
|
|
||||||
{
|
|
||||||
poolClass.TryPush(node1);
|
|
||||||
poolClass.TryPush(node2);
|
|
||||||
poolClass.TryPop(out _);
|
|
||||||
poolClass.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPoolWithoutSize()
|
|
||||||
{
|
|
||||||
poolWithoutSize.TryPush(node1);
|
|
||||||
poolWithoutSize.TryPush(node2);
|
|
||||||
poolWithoutSize.TryPop(out _);
|
|
||||||
poolWithoutSize.TryPop(out _);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Benchmark]
|
|
||||||
public void TaskPoolWithoutLock()
|
|
||||||
{
|
|
||||||
poolWithoutLock.TryPush(node1);
|
|
||||||
poolWithoutLock.TryPush(node2);
|
|
||||||
poolWithoutLock.TryPop(out _);
|
|
||||||
poolWithoutLock.TryPop(out _);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class Node : ITaskPoolNode<Node>
|
|
||||||
{
|
|
||||||
public Node NextNode { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
T NextNode { get; set; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed class RefNode :ITaskPoolRefNode<RefNode>
|
|
||||||
{
|
|
||||||
RefNode nextNode;
|
|
||||||
public ref RefNode NextNode => ref nextNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ITaskPoolRefNode<T>
|
|
||||||
{
|
|
||||||
ref T NextNode { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// mutable struct, don't mark readonly.
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
|
||||||
public struct TaskPoolWithoutLock<T>
|
|
||||||
where T : class, ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
public int Size => size;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
//if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (!(v is null))
|
|
||||||
{
|
|
||||||
root = v.NextNode;
|
|
||||||
v.NextNode = null;
|
|
||||||
size--;
|
|
||||||
result = v;
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
//if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
size++;
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
|
||||||
public struct TaskPool<T>
|
|
||||||
where T : class, ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
int gate;
|
|
||||||
int size;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
public int Size => size;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (!(v is null))
|
|
||||||
{
|
|
||||||
root = v.NextNode;
|
|
||||||
v.NextNode = null;
|
|
||||||
size--;
|
|
||||||
result = v;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
size++;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
|
||||||
public struct TaskPoolRefNode<T>
|
|
||||||
where T : class, ITaskPoolRefNode<T>
|
|
||||||
{
|
|
||||||
int gate;
|
|
||||||
int size;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
public int Size => size;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (!(v is null))
|
|
||||||
{
|
|
||||||
ref var nextNode = ref v.NextNode;
|
|
||||||
root = nextNode;
|
|
||||||
nextNode = null;
|
|
||||||
size--;
|
|
||||||
result = v;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
size++;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
|
||||||
public struct TaskPoolEqualNull<T>
|
|
||||||
where T : class, ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
int gate;
|
|
||||||
int size;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
public int Size => size;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (v != null)
|
|
||||||
{
|
|
||||||
root = v.NextNode;
|
|
||||||
v.NextNode = null;
|
|
||||||
size--;
|
|
||||||
result = v;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
size++;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class TaskPoolClass<T>
|
|
||||||
where T : class, ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
int gate;
|
|
||||||
int size;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
public int Size => size;
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (!(v is null))
|
|
||||||
{
|
|
||||||
root = v.NextNode;
|
|
||||||
v.NextNode = null;
|
|
||||||
size--;
|
|
||||||
result = v;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
size++;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Auto)]
|
|
||||||
public struct TaskPoolWithoutSize<T>
|
|
||||||
where T : class, ITaskPoolNode<T>
|
|
||||||
{
|
|
||||||
int gate;
|
|
||||||
T root;
|
|
||||||
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPop(out T result)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
var v = root;
|
|
||||||
if (!(v is null))
|
|
||||||
{
|
|
||||||
root = v.NextNode;
|
|
||||||
v.NextNode = null;
|
|
||||||
result = v;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
result = default;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
public bool TryPush(T item)
|
|
||||||
{
|
|
||||||
if (Interlocked.CompareExchange(ref gate, 1, 0) == 0)
|
|
||||||
{
|
|
||||||
//if (size < TaskPool.MaxPoolSize)
|
|
||||||
{
|
|
||||||
item.NextNode = root;
|
|
||||||
root = item;
|
|
||||||
Volatile.Write(ref gate, 0);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
//else
|
|
||||||
{
|
|
||||||
// Volatile.Write(ref gate, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
<RootNamespace>NetCoreSandbox</RootNamespace>
|
<RootNamespace>NetCoreSandbox</RootNamespace>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -15,6 +16,12 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\UniTask.NetCore\UniTask.NetCore.csproj" />
|
<ProjectReference Include="..\UniTask.NetCore\UniTask.NetCore.csproj" />
|
||||||
|
|
||||||
|
|
||||||
|
<ProjectReference Include="..\UniTask.Analyzer\UniTask.Analyzer.csproj">
|
||||||
|
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||||
|
<OutputItemType>Analyzer</OutputItemType>
|
||||||
|
</ProjectReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace NetCoreTests
|
|||||||
|
|
||||||
var ar = await array;
|
var ar = await array;
|
||||||
|
|
||||||
ar.Should().BeEquivalentTo(new[] { 99, 100, 100, 100, 131 });
|
ar.Should().Equal(new[] { 99, 100, 100, 100, 131 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -49,7 +49,7 @@ namespace NetCoreTests
|
|||||||
|
|
||||||
var ar = await array;
|
var ar = await array;
|
||||||
|
|
||||||
ar.Should().BeEquivalentTo(new[] { 100, 100, 100, 131, 191 });
|
ar.Should().Equal(new[] { 100, 100, 100, 131, 191 });
|
||||||
}
|
}
|
||||||
|
|
||||||
//[Fact]
|
//[Fact]
|
||||||
@@ -70,7 +70,7 @@ namespace NetCoreTests
|
|||||||
|
|
||||||
// var ar = await array;
|
// var ar = await array;
|
||||||
|
|
||||||
// ar.Should().BeEquivalentTo(new[] { 99, 100, 100, 100, 131 });
|
// ar.Should().Equal(new[] { 99, 100, 100, 100, 131 });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
//[Fact]
|
//[Fact]
|
||||||
@@ -88,7 +88,7 @@ namespace NetCoreTests
|
|||||||
|
|
||||||
// var ar = await array;
|
// var ar = await array;
|
||||||
|
|
||||||
// ar.Should().BeEquivalentTo(new[] { 100, 100, 100, 131, 191 });
|
// ar.Should().Equal(new[] { 100, 100, 100, 131, 191 });
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -276,8 +276,8 @@ namespace NetCoreTests
|
|||||||
reference.Writer.TryComplete();
|
reference.Writer.TryComplete();
|
||||||
channel.Writer.TryComplete();
|
channel.Writer.TryComplete();
|
||||||
|
|
||||||
(await ta1).Should().BeEquivalentTo(new[] { 10, 20, 30 });
|
(await ta1).Should().Equal(new[] { 10, 20, 30 });
|
||||||
(await ta2).Should().BeEquivalentTo(new[] { 10, 20, 30 });
|
(await ta2).Should().Equal(new[] { 10, 20, 30 });
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -481,7 +481,7 @@ namespace NetCoreTests.Linq
|
|||||||
list.Add(x);
|
list.Add(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
list.Should().BeEquivalentTo(Enumerable.Range(1, 10));
|
list.Should().Equal(Enumerable.Range(1, 10));
|
||||||
|
|
||||||
var list2 = new List<(int, int)>();
|
var list2 = new List<(int, int)>();
|
||||||
await Enumerable.Range(5, 10).ToUniTaskAsyncEnumerable().ForEachAsync((index, x) =>
|
await Enumerable.Range(5, 10).ToUniTaskAsyncEnumerable().ForEachAsync((index, x) =>
|
||||||
@@ -490,7 +490,7 @@ namespace NetCoreTests.Linq
|
|||||||
});
|
});
|
||||||
|
|
||||||
var list3 = Enumerable.Range(5, 10).Select((index, x) => (index, x)).ToArray();
|
var list3 = Enumerable.Range(5, 10).Select((index, x) => (index, x)).ToArray();
|
||||||
list2.Should().BeEquivalentTo(list3);
|
list2.Should().Equal(list3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Append(99).ToArrayAsync();
|
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Append(99).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(start, count).Append(99).ToArray();
|
var ys = Enumerable.Range(start, count).Append(99).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -50,7 +50,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Prepend(99).ToArrayAsync();
|
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Prepend(99).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(start, count).Prepend(99).ToArray();
|
var ys = Enumerable.Range(start, count).Prepend(99).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -85,7 +85,7 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
var xs = await l.ToUniTaskAsyncEnumerable().Concat(r.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
var xs = await l.ToUniTaskAsyncEnumerable().Concat(r.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
||||||
var ys = l.Concat(r).ToArray();
|
var ys = l.Concat(r).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -119,17 +119,17 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, 0).DefaultIfEmpty(99).ToArray();
|
var ys = Enumerable.Range(1, 0).DefaultIfEmpty(99).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 1).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
var xs = await Enumerable.Range(1, 1).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, 1).DefaultIfEmpty(99).ToArray();
|
var ys = Enumerable.Range(1, 1).DefaultIfEmpty(99).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 10).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
var xs = await Enumerable.Range(1, 10).ToUniTaskAsyncEnumerable().DefaultIfEmpty(99).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, 10).DefaultIfEmpty(99).ToArray();
|
var ys = Enumerable.Range(1, 10).DefaultIfEmpty(99).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
// Throw
|
// Throw
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,11 +34,11 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, 10).ToObservable().ToArray();
|
var xs = await UniTaskAsyncEnumerable.Range(1, 10).ToObservable().ToArray();
|
||||||
xs.Should().BeEquivalentTo(Enumerable.Range(1, 10));
|
xs.Should().Equal(Enumerable.Range(1, 10));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, 0).ToObservable().ToArray();
|
var xs = await UniTaskAsyncEnumerable.Range(1, 0).ToObservable().ToArray();
|
||||||
xs.Should().BeEquivalentTo(Enumerable.Range(1, 0));
|
xs.Should().Equal(Enumerable.Range(1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,21 +70,21 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Observable.Range(1, 100).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
var xs = await Observable.Range(1, 100).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
||||||
var ys = await Observable.Range(1, 100).ToArray();
|
var ys = await Observable.Range(1, 100).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var xs = await Observable.Range(1, 100, ThreadPoolScheduler.Instance).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
var xs = await Observable.Range(1, 100, ThreadPoolScheduler.Instance).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
||||||
var ys = await Observable.Range(1, 100, ThreadPoolScheduler.Instance).ToArray();
|
var ys = await Observable.Range(1, 100, ThreadPoolScheduler.Instance).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var xs = await Observable.Empty<int>(ThreadPoolScheduler.Instance).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
var xs = await Observable.Empty<int>(ThreadPoolScheduler.Instance).ToUniTaskAsyncEnumerable().ToArrayAsync();
|
||||||
var ys = await Observable.Empty<int>(ThreadPoolScheduler.Instance).ToArray();
|
var ys = await Observable.Empty<int>(ThreadPoolScheduler.Instance).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,25 +95,25 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x);
|
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x);
|
||||||
var ys = Enumerable.Range(1, 100).ToDictionary(x => x);
|
var ys = Enumerable.Range(1, 100).ToDictionary(x => x);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.OrderBy(x => x.Key).Should().Equal(ys.OrderBy(x => x.Key));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x);
|
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x);
|
||||||
var ys = Enumerable.Range(1, 0).ToDictionary(x => x);
|
var ys = Enumerable.Range(1, 0).ToDictionary(x => x);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.OrderBy(x => x.Key).Should().Equal(ys.OrderBy(x => x.Key));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x, x => x * 2);
|
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x, x => x * 2);
|
||||||
var ys = Enumerable.Range(1, 100).ToDictionary(x => x, x => x * 2);
|
var ys = Enumerable.Range(1, 100).ToDictionary(x => x, x => x * 2);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.OrderBy(x => x.Key).Should().Equal(ys.OrderBy(x => x.Key));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x, x => x * 2);
|
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToDictionaryAsync(x => x, x => x * 2);
|
||||||
var ys = Enumerable.Range(1, 0).ToDictionary(x => x, x => x * 2);
|
var ys = Enumerable.Range(1, 0).ToDictionary(x => x, x => x * 2);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.OrderBy(x => x.Key).Should().Equal(ys.OrderBy(x => x.Key));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,34 +126,34 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.ToLookup(x => x);
|
var ys = arr.ToLookup(x => x);
|
||||||
|
|
||||||
xs.Count.Should().Be(ys.Count);
|
xs.Count.Should().Be(ys.Count);
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
foreach (var key in xs.Select(x => x.Key))
|
foreach (var key in xs.Select(x => x.Key))
|
||||||
{
|
{
|
||||||
xs[key].Should().BeEquivalentTo(ys[key]);
|
xs[key].Should().Equal(ys[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToLookupAsync(x => x);
|
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToLookupAsync(x => x);
|
||||||
var ys = Enumerable.Range(1, 0).ToLookup(x => x);
|
var ys = Enumerable.Range(1, 0).ToLookup(x => x);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await arr.ToUniTaskAsyncEnumerable().ToLookupAsync(x => x, x => x * 2);
|
var xs = await arr.ToUniTaskAsyncEnumerable().ToLookupAsync(x => x, x => x * 2);
|
||||||
var ys = arr.ToLookup(x => x, x => x * 2);
|
var ys = arr.ToLookup(x => x, x => x * 2);
|
||||||
|
|
||||||
xs.Count.Should().Be(ys.Count);
|
xs.Count.Should().Be(ys.Count);
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
foreach (var key in xs.Select(x => x.Key))
|
foreach (var key in xs.Select(x => x.Key))
|
||||||
{
|
{
|
||||||
xs[key].Should().BeEquivalentTo(ys[key]);
|
xs[key].Should().Equal(ys[key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToLookupAsync(x => x, x => x * 2);
|
var xs = await Enumerable.Range(1, 0).ToUniTaskAsyncEnumerable().ToLookupAsync(x => x, x => x * 2);
|
||||||
var ys = Enumerable.Range(1, 0).ToLookup(x => x, x => x * 2);
|
var ys = Enumerable.Range(1, 0).ToLookup(x => x, x => x * 2);
|
||||||
|
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,13 +164,13 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToListAsync();
|
var xs = await Enumerable.Range(1, 100).ToUniTaskAsyncEnumerable().ToListAsync();
|
||||||
var ys = Enumerable.Range(1, 100).ToList();
|
var ys = Enumerable.Range(1, 100).ToList();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Empty<int>().ToUniTaskAsyncEnumerable().ToListAsync();
|
var xs = await Enumerable.Empty<int>().ToUniTaskAsyncEnumerable().ToListAsync();
|
||||||
var ys = Enumerable.Empty<int>().ToList();
|
var ys = Enumerable.Empty<int>().ToList();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,13 +181,13 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await new[] { 1, 20, 4, 5, 20, 4, 6 }.ToUniTaskAsyncEnumerable().ToHashSetAsync();
|
var xs = await new[] { 1, 20, 4, 5, 20, 4, 6 }.ToUniTaskAsyncEnumerable().ToHashSetAsync();
|
||||||
var ys = new[] { 1, 20, 4, 5, 20, 4, 6 }.ToHashSet();
|
var ys = new[] { 1, 20, 4, 5, 20, 4, 6 }.ToHashSet();
|
||||||
|
|
||||||
xs.OrderBy(x => x).Should().BeEquivalentTo(ys.OrderBy(x => x));
|
xs.OrderBy(x => x).Should().Equal(ys.OrderBy(x => x));
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await Enumerable.Empty<int>().ToUniTaskAsyncEnumerable().ToHashSetAsync();
|
var xs = await Enumerable.Empty<int>().ToUniTaskAsyncEnumerable().ToHashSetAsync();
|
||||||
var ys = Enumerable.Empty<int>().ToHashSet();
|
var ys = Enumerable.Empty<int>().ToHashSet();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
var ys = await Range(from, count).AsUniTaskAsyncEnumerable().ToArrayAsync();
|
var ys = await Range(from, count).AsUniTaskAsyncEnumerable().ToArrayAsync();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -57,19 +57,19 @@ namespace NetCoreTests.Linq
|
|||||||
list.Should().BeEmpty();
|
list.Should().BeEmpty();
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100);
|
list.Should().Equal(100);
|
||||||
e.Current.Should().Be(10);
|
e.Current.Should().Be(10);
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100, 200);
|
list.Should().Equal(100, 200);
|
||||||
e.Current.Should().Be(20);
|
e.Current.Should().Be(20);
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100, 200, 300);
|
list.Should().Equal(100, 200, 300);
|
||||||
e.Current.Should().Be(30);
|
e.Current.Should().Be(30);
|
||||||
|
|
||||||
(await e.MoveNextAsync()).Should().BeFalse();
|
(await e.MoveNextAsync()).Should().BeFalse();
|
||||||
list.Should().BeEquivalentTo(100, 200, 300, 400);
|
list.Should().Equal(100, 200, 300, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -144,19 +144,19 @@ namespace NetCoreTests.Linq
|
|||||||
list.Should().BeEmpty();
|
list.Should().BeEmpty();
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100);
|
list.Should().Equal(100);
|
||||||
e.Current.Should().Be(10);
|
e.Current.Should().Be(10);
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100, 200);
|
list.Should().Equal(100, 200);
|
||||||
e.Current.Should().Be(20);
|
e.Current.Should().Be(20);
|
||||||
|
|
||||||
await e.MoveNextAsync();
|
await e.MoveNextAsync();
|
||||||
list.Should().BeEquivalentTo(100, 200, 300);
|
list.Should().Equal(100, 200, 300);
|
||||||
e.Current.Should().Be(30);
|
e.Current.Should().Be(30);
|
||||||
|
|
||||||
(await e.MoveNextAsync()).Should().BeFalse();
|
(await e.MoveNextAsync()).Should().BeFalse();
|
||||||
list.Should().BeEquivalentTo(100, 200, 300, 400);
|
list.Should().Equal(100, 200, 300, 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
async IAsyncEnumerable<int> Range(int from, int count)
|
async IAsyncEnumerable<int> Range(int from, int count)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(start, count).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(start, count).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(start, count).ToArray();
|
var ys = Enumerable.Range(start, count).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -36,7 +36,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Repeat(value, count).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Repeat(value, count).ToArrayAsync();
|
||||||
var ys = Enumerable.Repeat(value, count).ToArray();
|
var ys = Enumerable.Repeat(value, count).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -45,7 +45,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Empty<int>().ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Empty<int>().ToArrayAsync();
|
||||||
var ys = Enumerable.Empty<int>().ToArray();
|
var ys = Enumerable.Empty<int>().ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|||||||
@@ -23,26 +23,26 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var a = await src.Where(x => x % 2 == 0).ToArrayAsync();
|
var a = await src.Where(x => x % 2 == 0).ToArrayAsync();
|
||||||
var expected = range.Where(x => x % 2 == 0).ToArray();
|
var expected = range.Where(x => x % 2 == 0).ToArray();
|
||||||
a.Should().BeEquivalentTo(expected);
|
a.Should().Equal(expected);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var a = await src.Where((x, i) => (x + i) % 2 == 0).ToArrayAsync();
|
var a = await src.Where((x, i) => (x + i) % 2 == 0).ToArrayAsync();
|
||||||
var expected = range.Where((x, i) => (x + i) % 2 == 0).ToArray();
|
var expected = range.Where((x, i) => (x + i) % 2 == 0).ToArray();
|
||||||
a.Should().BeEquivalentTo(expected);
|
a.Should().Equal(expected);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var a = await src.WhereAwait(x => UniTask.Run(() => x % 2 == 0)).ToArrayAsync();
|
var a = await src.WhereAwait(x => UniTask.Run(() => x % 2 == 0)).ToArrayAsync();
|
||||||
var b = await src.WhereAwait(x => UniTask.FromResult(x % 2 == 0)).ToArrayAsync();
|
var b = await src.WhereAwait(x => UniTask.FromResult(x % 2 == 0)).ToArrayAsync();
|
||||||
var expected = range.Where(x => x % 2 == 0).ToArray();
|
var expected = range.Where(x => x % 2 == 0).ToArray();
|
||||||
a.Should().BeEquivalentTo(expected);
|
a.Should().Equal(expected);
|
||||||
b.Should().BeEquivalentTo(expected);
|
b.Should().Equal(expected);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var a = await src.WhereAwait((x, i) => UniTask.Run(() => (x + i) % 2 == 0)).ToArrayAsync();
|
var a = await src.WhereAwait((x, i) => UniTask.Run(() => (x + i) % 2 == 0)).ToArrayAsync();
|
||||||
var b = await src.WhereAwait((x, i) => UniTask.FromResult((x + i) % 2 == 0)).ToArrayAsync();
|
var b = await src.WhereAwait((x, i) => UniTask.FromResult((x + i) % 2 == 0)).ToArrayAsync();
|
||||||
var expected = range.Where((x, i) => (x + i) % 2 == 0).ToArray();
|
var expected = range.Where((x, i) => (x + i) % 2 == 0).ToArray();
|
||||||
a.Should().BeEquivalentTo(expected);
|
a.Should().Equal(expected);
|
||||||
b.Should().BeEquivalentTo(expected);
|
b.Should().Equal(expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace NetCoreTests.Linq
|
|||||||
var a = await data.ToUniTaskAsyncEnumerable().OfType<int>().ToArrayAsync();
|
var a = await data.ToUniTaskAsyncEnumerable().OfType<int>().ToArrayAsync();
|
||||||
var b = data.OfType<int>().ToArray();
|
var b = data.OfType<int>().ToArray();
|
||||||
|
|
||||||
a.Should().BeEquivalentTo(b);
|
a.Should().Equal(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ namespace NetCoreTests.Linq
|
|||||||
var a = await data.ToUniTaskAsyncEnumerable().Cast<int>().ToArrayAsync();
|
var a = await data.ToUniTaskAsyncEnumerable().Cast<int>().ToArrayAsync();
|
||||||
var b = data.Cast<int>().ToArray();
|
var b = data.Cast<int>().ToArray();
|
||||||
|
|
||||||
a.Should().BeEquivalentTo(b);
|
a.Should().Equal(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await outer.ToUniTaskAsyncEnumerable().Join(inner.ToUniTaskAsyncEnumerable(), x => x, x => x, (x, y) => (x, y)).ToArrayAsync();
|
var xs = await outer.ToUniTaskAsyncEnumerable().Join(inner.ToUniTaskAsyncEnumerable(), x => x, x => x, (x, y) => (x, y)).ToArrayAsync();
|
||||||
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await outer.ToUniTaskAsyncEnumerable().JoinAwait(inner.ToUniTaskAsyncEnumerable(), x => RandomRun(x), x => RandomRun(x), (x, y) => RandomRun((x, y))).ToArrayAsync();
|
var xs = await outer.ToUniTaskAsyncEnumerable().JoinAwait(inner.ToUniTaskAsyncEnumerable(), x => RandomRun(x), x => RandomRun(x), (x, y) => RandomRun((x, y))).ToArrayAsync();
|
||||||
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await outer.ToUniTaskAsyncEnumerable().JoinAwaitWithCancellation(inner.ToUniTaskAsyncEnumerable(), (x, _) => RandomRun(x), (x, _) => RandomRun(x), (x, y, _) => RandomRun((x, y))).ToArrayAsync();
|
var xs = await outer.ToUniTaskAsyncEnumerable().JoinAwaitWithCancellation(inner.ToUniTaskAsyncEnumerable(), (x, _) => RandomRun(x), (x, _) => RandomRun(x), (x, y, _) => RandomRun((x, y))).ToArrayAsync();
|
||||||
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
var ys = outer.Join(inner, x => x, x => x, (x, y) => (x, y)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +123,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x).ToArray();
|
var ys = arr.GroupBy(x => x).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -131,7 +131,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().BeEquivalentTo(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().Equal(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -139,7 +139,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x).ToArray();
|
var ys = arr.GroupBy(x => x).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -147,7 +147,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().BeEquivalentTo(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().Equal(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -155,7 +155,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x).ToArray();
|
var ys = arr.GroupBy(x => x).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.Key).Should().BeEquivalentTo(ys.OrderBy(x => x.Key));
|
xs.Should().BeEquivalentTo(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -163,7 +163,7 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
var ys = arr.GroupBy(x => x, (key, xs) => (key, xs.ToArray())).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().BeEquivalentTo(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
xs.OrderBy(x => x.key).SelectMany(x => x.Item2).Should().Equal(ys.OrderBy(x => x.key).SelectMany(x => x.Item2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,21 +199,21 @@ namespace NetCoreTests.Linq
|
|||||||
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await outer.ToUniTaskAsyncEnumerable().GroupJoinAwait(inner.ToUniTaskAsyncEnumerable(), x => RandomRun(x), x => RandomRun(x), (x, y) => RandomRun((x, string.Join(", ", y)))).ToArrayAsync();
|
var xs = await outer.ToUniTaskAsyncEnumerable().GroupJoinAwait(inner.ToUniTaskAsyncEnumerable(), x => RandomRun(x), x => RandomRun(x), (x, y) => RandomRun((x, string.Join(", ", y)))).ToArrayAsync();
|
||||||
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await outer.ToUniTaskAsyncEnumerable().GroupJoinAwaitWithCancellation(inner.ToUniTaskAsyncEnumerable(), (x, _) => RandomRun(x), (x, _) => RandomRun(x), (x, y, _) => RandomRun((x, string.Join(", ", y)))).ToArrayAsync();
|
var xs = await outer.ToUniTaskAsyncEnumerable().GroupJoinAwaitWithCancellation(inner.ToUniTaskAsyncEnumerable(), (x, _) => RandomRun(x), (x, _) => RandomRun(x), (x, y, _) => RandomRun((x, string.Join(", ", y)))).ToArrayAsync();
|
||||||
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
var ys = outer.GroupJoin(inner, x => x, x => x, (x, y) => (x, string.Join(", ", y))).ToArray();
|
||||||
|
|
||||||
xs.Length.Should().Be(ys.Length);
|
xs.Length.Should().Be(ys.Length);
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).Skip(skipCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).Skip(skipCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).Skip(skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).Skip(skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -52,7 +52,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipLast(skipCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipLast(skipCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipLast(skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipLast(skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -77,7 +77,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeLast(takeCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeLast(takeCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeLast(takeCount).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeLast(takeCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -103,7 +103,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).Take(takeCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).Take(takeCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).Take(takeCount).ToArray();
|
var ys = Enumerable.Range(1, collection).Take(takeCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -130,37 +130,37 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwait(x => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwait(x => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwait((x, i) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwait((x, i) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwaitWithCancellation((x, _) => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwaitWithCancellation((x, _) => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwaitWithCancellation((x, i, _) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).SkipWhileAwaitWithCancellation((x, i, _) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).SkipWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,37 +213,37 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwait(x => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwait(x => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwait((x, i) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwait((x, i) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwaitWithCancellation((x, _) => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwaitWithCancellation((x, _) => UniTask.Run(() => x < skipCount)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile(x => x < skipCount).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwaitWithCancellation((x, i, _) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, collection).TakeWhileAwaitWithCancellation((x, i, _) => UniTask.Run(() => x < (skipCount - i))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
var ys = Enumerable.Range(1, collection).TakeWhile((x, i) => x < (skipCount - i)).ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Reverse().ToArrayAsync();
|
var xs = await Enumerable.Range(start, count).ToUniTaskAsyncEnumerable().Reverse().ToArrayAsync();
|
||||||
var ys = Enumerable.Range(start, count).Reverse().ToArray();
|
var ys = Enumerable.Range(start, count).Reverse().ToArray();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -46,18 +46,18 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, count).Select(x => x * x).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, count).Select(x => x * x).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, count).Select(x => x * x).ToArray();
|
var ys = Enumerable.Range(1, count).Select(x => x * x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
|
|
||||||
var zs = await UniTaskAsyncEnumerable.Range(1, count).SelectAwait((x) => UniTask.Run(() => x * x)).ToArrayAsync();
|
var zs = await UniTaskAsyncEnumerable.Range(1, count).SelectAwait((x) => UniTask.Run(() => x * x)).ToArrayAsync();
|
||||||
zs.Should().BeEquivalentTo(ys);
|
zs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, count).Select((x, i) => x * x * i).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, count).Select((x, i) => x * x * i).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, count).Select((x, i) => x * x * i).ToArray();
|
var ys = Enumerable.Range(1, count).Select((x, i) => x * x * i).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
|
|
||||||
var zs = await UniTaskAsyncEnumerable.Range(1, count).SelectAwait((x, i) => UniTask.Run(() => x * x * i)).ToArrayAsync();
|
var zs = await UniTaskAsyncEnumerable.Range(1, count).SelectAwait((x, i) => UniTask.Run(() => x * x * i)).ToArrayAsync();
|
||||||
zs.Should().BeEquivalentTo(ys);
|
zs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,22 +98,22 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany(x => UniTaskAsyncEnumerable.Range(99, rightCount * x)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany(x => UniTaskAsyncEnumerable.Range(99, rightCount * x)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany((i, x) => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany((i, x) => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany(x => UniTaskAsyncEnumerable.Range(99, rightCount * x), (x, y) => x * y).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany(x => UniTaskAsyncEnumerable.Range(99, rightCount * x), (x, y) => x * y).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany((i, x) => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectMany((i, x) => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// await
|
// await
|
||||||
@@ -121,22 +121,22 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait(x => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait(x => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait((i, x) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait((i, x) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait(x => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x)), (x, y) => UniTask.Run(() => x * y)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait(x => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x)), (x, y) => UniTask.Run(() => x * y)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait((i, x) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)), (x, y) => UniTask.Run(() => x * y)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwait((i, x) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)), (x, y) => UniTask.Run(() => x * y)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
// with cancel
|
// with cancel
|
||||||
@@ -144,22 +144,22 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((i, x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((i, x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x)), (x, y, _) => UniTask.Run(() => x * y)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99, rightCount * x)), (x, y, _) => UniTask.Run(() => x * y)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany(x => Enumerable.Range(99, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((i, x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)), (x, y, _) => UniTask.Run(() => x * y)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).SelectManyAwaitWithCancellation((i, x, _) => UniTask.Run(() => UniTaskAsyncEnumerable.Range(99 * i, rightCount * x)), (x, y, _) => UniTask.Run(() => x * y)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
var ys = Enumerable.Range(1, leftCount).SelectMany((i, x) => Enumerable.Range(99 * i, rightCount * x), (x, y) => x * y).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,17 +219,17 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).Zip(UniTaskAsyncEnumerable.Range(99, rightCount)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).Zip(UniTaskAsyncEnumerable.Range(99, rightCount)).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).ZipAwait(UniTaskAsyncEnumerable.Range(99, rightCount), (x, y) => UniTask.Run(() => (x, y))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).ZipAwait(UniTaskAsyncEnumerable.Range(99, rightCount), (x, y) => UniTask.Run(() => (x, y))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).ZipAwaitWithCancellation(UniTaskAsyncEnumerable.Range(99, rightCount), (x, y, _) => UniTask.Run(() => (x, y))).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, leftCount).ZipAwaitWithCancellation(UniTaskAsyncEnumerable.Range(99, rightCount), (x, y, _) => UniTask.Run(() => (x, y))).ToArrayAsync();
|
||||||
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
var ys = Enumerable.Range(1, leftCount).Zip(Enumerable.Range(99, rightCount)).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -288,7 +288,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
||||||
var ys = await AsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
var ys = await AsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -305,7 +305,7 @@ namespace NetCoreTests.Linq
|
|||||||
var xs = await UniTaskAsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount, skipCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount, skipCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
||||||
var ys = await AsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount, skipCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
var ys = await AsyncEnumerable.Range(0, rangeCount).Buffer(bufferCount, skipCount).Select(x => string.Join(",", x)).ToArrayAsync();
|
||||||
|
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -402,7 +402,7 @@ namespace NetCoreTests.Linq
|
|||||||
public async Task PariwiseImmediate()
|
public async Task PariwiseImmediate()
|
||||||
{
|
{
|
||||||
var xs = await UniTaskAsyncEnumerable.Range(1, 5).Pairwise().ToArrayAsync();
|
var xs = await UniTaskAsyncEnumerable.Range(1, 5).Pairwise().ToArrayAsync();
|
||||||
xs.Should().BeEquivalentTo((1, 2), (2, 3), (3, 4), (4, 5));
|
xs.Should().Equal((1, 2), (2, 3), (3, 4), (4, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -426,7 +426,7 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
await complete;
|
await complete;
|
||||||
|
|
||||||
list.Should().BeEquivalentTo((10, 20), (20, 30), (30, 40), (40, 50));
|
list.Should().Equal((10, 20), (20, 30), (30, 40), (40, 50));
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyException : Exception
|
class MyException : Exception
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
rp.Value = 2;
|
rp.Value = 2;
|
||||||
|
|
||||||
(await b).Should().BeEquivalentTo(1, 2);
|
(await b).Should().Equal(1, 2);
|
||||||
|
|
||||||
var c = multicast.ToArrayAsync();
|
var c = multicast.ToArrayAsync();
|
||||||
|
|
||||||
@@ -36,8 +36,8 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
rp.Dispose();
|
rp.Dispose();
|
||||||
|
|
||||||
(await a).Should().BeEquivalentTo(1, 2, 3, 4, 5);
|
(await a).Should().Equal(1, 2, 3, 4, 5);
|
||||||
(await c).Should().BeEquivalentTo(3, 4, 5);
|
(await c).Should().Equal(3, 4, 5);
|
||||||
|
|
||||||
disp.Dispose();
|
disp.Dispose();
|
||||||
}
|
}
|
||||||
@@ -56,7 +56,7 @@ namespace NetCoreTests.Linq
|
|||||||
|
|
||||||
rp.Value = 2;
|
rp.Value = 2;
|
||||||
|
|
||||||
(await b).Should().BeEquivalentTo(1, 2);
|
(await b).Should().Equal(1, 2);
|
||||||
|
|
||||||
var c = multicast.ToArrayAsync();
|
var c = multicast.ToArrayAsync();
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ namespace NetCoreTests.Linq
|
|||||||
l.Add(x);
|
l.Add(x);
|
||||||
});
|
});
|
||||||
|
|
||||||
l.Should().BeEquivalentTo(100, 110, 120, 130, 140, 150, 160, 170, 180, 190);
|
l.Should().Equal(100, 110, 120, 130, 140, 150, 160, 170, 180, 190);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var ys = array.Distinct().ToArray();
|
var ys = array.Distinct().ToArray();
|
||||||
{
|
{
|
||||||
(await array.ToUniTaskAsyncEnumerable().Distinct().ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().Distinct().ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().Distinct(x => x).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().Distinct(x => x).ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctAwait(x => UniTask.Run(() => x)).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctAwait(x => UniTask.Run(() => x)).ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctAwaitWithCancellation((x, _) => UniTask.Run(() => x)).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctAwaitWithCancellation((x, _) => UniTask.Run(() => x)).ToArrayAsync()).Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,10 +71,10 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var ys = await array.ToAsyncEnumerable().DistinctUntilChanged().ToArrayAsync();
|
var ys = await array.ToAsyncEnumerable().DistinctUntilChanged().ToArrayAsync();
|
||||||
{
|
{
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChanged().ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChanged().ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChanged(x => x).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChanged(x => x).ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChangedAwait(x => UniTask.Run(() => x)).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChangedAwait(x => UniTask.Run(() => x)).ToArrayAsync()).Should().Equal(ys);
|
||||||
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChangedAwaitWithCancellation((x, _) => UniTask.Run(() => x)).ToArrayAsync()).Should().BeEquivalentTo(ys);
|
(await array.ToUniTaskAsyncEnumerable().DistinctUntilChangedAwaitWithCancellation((x, _) => UniTask.Run(() => x)).ToArrayAsync()).Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +112,7 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await a1.ToUniTaskAsyncEnumerable().Except(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
var xs = await a1.ToUniTaskAsyncEnumerable().Except(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
||||||
var ys = a1.Except(a2).ToArray();
|
var ys = a1.Except(a2).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await a1.ToUniTaskAsyncEnumerable().Intersect(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
var xs = await a1.ToUniTaskAsyncEnumerable().Intersect(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
||||||
var ys = a1.Intersect(a2).ToArray();
|
var ys = a1.Intersect(a2).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await a1.ToUniTaskAsyncEnumerable().Union(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
var xs = await a1.ToUniTaskAsyncEnumerable().Union(a2.ToUniTaskAsyncEnumerable()).ToArrayAsync();
|
||||||
var ys = a1.Union(a2).ToArray();
|
var ys = a1.Union(a2).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,32 +59,32 @@ namespace NetCoreTests.Linq
|
|||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderBy(x => x).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderBy(x => x).ToArrayAsync();
|
||||||
var ys = array.OrderBy(x => x).ToArray();
|
var ys = array.OrderBy(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x).ToArrayAsync();
|
||||||
var ys = array.OrderByDescending(x => x).ToArray();
|
var ys = array.OrderByDescending(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderByAwait(RandomRun).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderByAwait(RandomRun).ToArrayAsync();
|
||||||
var ys = array.OrderBy(x => x).ToArray();
|
var ys = array.OrderBy(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(RandomRun).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(RandomRun).ToArrayAsync();
|
||||||
var ys = array.OrderByDescending(x => x).ToArray();
|
var ys = array.OrderByDescending(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderByAwaitWithCancellation(RandomRun).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderByAwaitWithCancellation(RandomRun).ToArrayAsync();
|
||||||
var ys = array.OrderBy(x => x).ToArray();
|
var ys = array.OrderBy(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation(RandomRun).ToArrayAsync();
|
var xs = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation(RandomRun).ToArrayAsync();
|
||||||
var ys = array.OrderByDescending(x => x).ToArray();
|
var ys = array.OrderByDescending(x => x).ToArray();
|
||||||
xs.Should().BeEquivalentTo(ys);
|
xs.Should().Equal(ys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,14 +125,14 @@ namespace NetCoreTests.Linq
|
|||||||
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x.Age).ThenByDescending(x => x.FirstName).ThenBy(x => x.LastName).ToArrayAsync();
|
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x.Age).ThenByDescending(x => x.FirstName).ThenBy(x => x.LastName).ToArrayAsync();
|
||||||
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x.Age).ThenByDescending(x => x.FirstName).ThenByDescending(x => x.LastName).ToArrayAsync();
|
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescending(x => x.Age).ThenByDescending(x => x.FirstName).ThenByDescending(x => x.LastName).ToArrayAsync();
|
||||||
|
|
||||||
a.Should().BeEquivalentTo(a2);
|
a.Should().Equal(a2);
|
||||||
b.Should().BeEquivalentTo(b2);
|
b.Should().Equal(b2);
|
||||||
c.Should().BeEquivalentTo(c2);
|
c.Should().Equal(c2);
|
||||||
d.Should().BeEquivalentTo(d2);
|
d.Should().Equal(d2);
|
||||||
e.Should().BeEquivalentTo(e2);
|
e.Should().Equal(e2);
|
||||||
f.Should().BeEquivalentTo(f2);
|
f.Should().Equal(f2);
|
||||||
g.Should().BeEquivalentTo(g2);
|
g.Should().Equal(g2);
|
||||||
h.Should().BeEquivalentTo(h2);
|
h.Should().Equal(h2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var a2 = await array.ToUniTaskAsyncEnumerable().OrderByAwait(x => RandomRun(x.Age)).ThenByAwait(x => RandomRun(x.FirstName)).ThenByAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
var a2 = await array.ToUniTaskAsyncEnumerable().OrderByAwait(x => RandomRun(x.Age)).ThenByAwait(x => RandomRun(x.FirstName)).ThenByAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
@@ -144,14 +144,14 @@ namespace NetCoreTests.Linq
|
|||||||
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(x => RandomRun(x.Age)).ThenByDescendingAwait(x => RandomRun(x.FirstName)).ThenByAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(x => RandomRun(x.Age)).ThenByDescendingAwait(x => RandomRun(x.FirstName)).ThenByAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(x => RandomRun(x.Age)).ThenByDescendingAwait(x => RandomRun(x.FirstName)).ThenByDescendingAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwait(x => RandomRun(x.Age)).ThenByDescendingAwait(x => RandomRun(x.FirstName)).ThenByDescendingAwait(x => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
|
|
||||||
a.Should().BeEquivalentTo(a2);
|
a.Should().Equal(a2);
|
||||||
b.Should().BeEquivalentTo(b2);
|
b.Should().Equal(b2);
|
||||||
c.Should().BeEquivalentTo(c2);
|
c.Should().Equal(c2);
|
||||||
d.Should().BeEquivalentTo(d2);
|
d.Should().Equal(d2);
|
||||||
e.Should().BeEquivalentTo(e2);
|
e.Should().Equal(e2);
|
||||||
f.Should().BeEquivalentTo(f2);
|
f.Should().Equal(f2);
|
||||||
g.Should().BeEquivalentTo(g2);
|
g.Should().Equal(g2);
|
||||||
h.Should().BeEquivalentTo(h2);
|
h.Should().Equal(h2);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
var a2 = await array.ToUniTaskAsyncEnumerable().OrderByAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
var a2 = await array.ToUniTaskAsyncEnumerable().OrderByAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
@@ -163,14 +163,14 @@ namespace NetCoreTests.Linq
|
|||||||
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
var g2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
var h2 = await array.ToUniTaskAsyncEnumerable().OrderByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.Age)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.FirstName)).ThenByDescendingAwaitWithCancellation((x, ct) => RandomRun(x.LastName)).ToArrayAsync();
|
||||||
|
|
||||||
a.Should().BeEquivalentTo(a2);
|
a.Should().Equal(a2);
|
||||||
b.Should().BeEquivalentTo(b2);
|
b.Should().Equal(b2);
|
||||||
c.Should().BeEquivalentTo(c2);
|
c.Should().Equal(c2);
|
||||||
d.Should().BeEquivalentTo(d2);
|
d.Should().Equal(d2);
|
||||||
e.Should().BeEquivalentTo(e2);
|
e.Should().Equal(e2);
|
||||||
f.Should().BeEquivalentTo(f2);
|
f.Should().Equal(f2);
|
||||||
g.Should().BeEquivalentTo(g2);
|
g.Should().Equal(g2);
|
||||||
h.Should().BeEquivalentTo(h2);
|
h.Should().Equal(h2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace NetCoreTests.Linq
|
|||||||
rp.Value = 4;
|
rp.Value = 4;
|
||||||
rp.Value = 5;
|
rp.Value = 5;
|
||||||
|
|
||||||
(await xs).Should().BeEquivalentTo(1, 2, 3, 4, 5);
|
(await xs).Should().Equal(1, 2, 3, 4, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -39,7 +39,7 @@ namespace NetCoreTests.Linq
|
|||||||
rp.Value = 4;
|
rp.Value = 4;
|
||||||
rp.Value = 5;
|
rp.Value = 5;
|
||||||
|
|
||||||
(await xs).Should().BeEquivalentTo(1, 2, 3, 4);
|
(await xs).Should().Equal(1, 2, 3, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -56,7 +56,7 @@ namespace NetCoreTests.Linq
|
|||||||
await c;
|
await c;
|
||||||
var foo = await xs;
|
var foo = await xs;
|
||||||
|
|
||||||
foo.Should().BeEquivalentTo(new[] { 1, 10, 20 });
|
foo.Should().Equal(new[] { 1, 10, 20 });
|
||||||
|
|
||||||
async Task CancelAsync()
|
async Task CancelAsync()
|
||||||
{
|
{
|
||||||
@@ -85,7 +85,7 @@ namespace NetCoreTests.Linq
|
|||||||
await c;
|
await c;
|
||||||
var foo = await xs;
|
var foo = await xs;
|
||||||
|
|
||||||
foo.Should().BeEquivalentTo(new[] { 20, 30, 40 });
|
foo.Should().Equal(new[] { 20, 30, 40 });
|
||||||
|
|
||||||
async Task CancelAsync()
|
async Task CancelAsync()
|
||||||
{
|
{
|
||||||
@@ -116,7 +116,7 @@ namespace NetCoreTests.Linq
|
|||||||
await c;
|
await c;
|
||||||
var foo = await xs;
|
var foo = await xs;
|
||||||
|
|
||||||
foo.Should().BeEquivalentTo(new[] { 1, 10, 20 });
|
foo.Should().Equal(new[] { 1, 10, 20 });
|
||||||
|
|
||||||
async Task CancelAsync()
|
async Task CancelAsync()
|
||||||
{
|
{
|
||||||
@@ -145,7 +145,7 @@ namespace NetCoreTests.Linq
|
|||||||
await c;
|
await c;
|
||||||
var foo = await xs;
|
var foo = await xs;
|
||||||
|
|
||||||
foo.Should().BeEquivalentTo(new[] { 20, 30, 40 });
|
foo.Should().Equal(new[] { 20, 30, 40 });
|
||||||
|
|
||||||
async Task CancelAsync()
|
async Task CancelAsync()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ namespace NetCoreTests
|
|||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
ev.SetCanceled(default);
|
ev.SetCanceled(default);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
one.CompletedCalled.Count.Should().Be(1);
|
one.CompletedCalled.Count.Should().Be(1);
|
||||||
}
|
}
|
||||||
// after removed, onemore
|
// after removed, onemore
|
||||||
@@ -59,7 +59,7 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ namespace NetCoreTests
|
|||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
ev.SetCanceled(default);
|
ev.SetCanceled(default);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
one.CompletedCalled.Count.Should().Be(1);
|
one.CompletedCalled.Count.Should().Be(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -102,10 +102,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
four.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
four.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
|
|
||||||
@@ -120,11 +120,11 @@ namespace NetCoreTests
|
|||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
ev.SetCanceled(default);
|
ev.SetCanceled(default);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
one.CompletedCalled.Count.Should().Be(1);
|
one.CompletedCalled.Count.Should().Be(1);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.CompletedCalled.Count.Should().Be(1);
|
three.CompletedCalled.Count.Should().Be(1);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.CompletedCalled.Count.Should().Be(1);
|
three.CompletedCalled.Count.Should().Be(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,10 +145,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
ev.Add(four);
|
ev.Add(four);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
four.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
four.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
|
|
||||||
@@ -163,11 +163,11 @@ namespace NetCoreTests
|
|||||||
ev.SetCompleted();
|
ev.SetCompleted();
|
||||||
ev.SetCanceled(default);
|
ev.SetCanceled(default);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
one.CompletedCalled.Count.Should().Be(1);
|
one.CompletedCalled.Count.Should().Be(1);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.CompletedCalled.Count.Should().Be(1);
|
three.CompletedCalled.Count.Should().Be(1);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.CompletedCalled.Count.Should().Be(1);
|
three.CompletedCalled.Count.Should().Be(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -190,9 +190,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.Remove(one);
|
ev.Remove(one);
|
||||||
|
|
||||||
@@ -200,9 +200,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(50);
|
ev.SetResult(50);
|
||||||
ev.SetResult(60);
|
ev.SetResult(60);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
two.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
three.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -222,9 +222,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.Remove(two);
|
ev.Remove(two);
|
||||||
|
|
||||||
@@ -232,9 +232,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(50);
|
ev.SetResult(50);
|
||||||
ev.SetResult(60);
|
ev.SetResult(60);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
one.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
three.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -254,9 +254,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
|
|
||||||
ev.Remove(three);
|
ev.Remove(three);
|
||||||
|
|
||||||
@@ -264,9 +264,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(50);
|
ev.SetResult(50);
|
||||||
ev.SetResult(60);
|
ev.SetResult(60);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
one.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40, 50, 60);
|
two.NextCalled.Should().Equal(10, 20, 30, 40, 50, 60);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,9 +321,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10);
|
one.NextCalled.Should().Equal(10);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run2()
|
public void Run2()
|
||||||
@@ -342,9 +342,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10);
|
one.NextCalled.Should().Equal(10);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run3()
|
public void Run3()
|
||||||
@@ -363,9 +363,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10);
|
one.NextCalled.Should().Equal(10);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
two.NextCalled.Should().Equal(10, 20, 30);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -390,9 +390,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Count.Should().Be(0);
|
two.NextCalled.Count.Should().Be(0);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run2()
|
public void Run2()
|
||||||
@@ -412,9 +412,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10);
|
two.NextCalled.Should().Equal(10);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run3()
|
public void Run3()
|
||||||
@@ -434,9 +434,9 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Should().BeEquivalentTo(10);
|
two.NextCalled.Should().Equal(10);
|
||||||
three.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
three.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,10 +464,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
one.NextCalled.Should().Equal(10, 20, 30);
|
||||||
two.NextCalled.Count.Should().Be(0);
|
two.NextCalled.Count.Should().Be(0);
|
||||||
three.NextCalled.Count.Should().Be(0);
|
three.NextCalled.Count.Should().Be(0);
|
||||||
four.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
four.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run2()
|
public void Run2()
|
||||||
@@ -490,10 +490,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(20);
|
ev.SetResult(20);
|
||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10);
|
one.NextCalled.Should().Equal(10);
|
||||||
two.NextCalled.Count.Should().Be(0);
|
two.NextCalled.Count.Should().Be(0);
|
||||||
three.NextCalled.Count.Should().Be(0);
|
three.NextCalled.Count.Should().Be(0);
|
||||||
four.NextCalled.Should().BeEquivalentTo(10, 20, 30);
|
four.NextCalled.Should().Equal(10, 20, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -533,10 +533,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
ev.SetResult(40);
|
ev.SetResult(40);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40);
|
one.NextCalled.Should().Equal(10, 20, 30, 40);
|
||||||
two.NextCalled.Should().BeEquivalentTo(20, 30, 40);
|
two.NextCalled.Should().Equal(20, 30, 40);
|
||||||
three.NextCalled.Should().BeEquivalentTo(30, 40);
|
three.NextCalled.Should().Equal(30, 40);
|
||||||
four.NextCalled.Should().BeEquivalentTo(40);
|
four.NextCalled.Should().Equal(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Run2()
|
public void Run2()
|
||||||
@@ -573,10 +573,10 @@ namespace NetCoreTests
|
|||||||
ev.SetResult(30);
|
ev.SetResult(30);
|
||||||
ev.SetResult(40);
|
ev.SetResult(40);
|
||||||
|
|
||||||
one.NextCalled.Should().BeEquivalentTo(10, 20, 30, 40);
|
one.NextCalled.Should().Equal(10, 20, 30, 40);
|
||||||
two.NextCalled.Should().BeEquivalentTo(20, 30, 40);
|
two.NextCalled.Should().Equal(20, 30, 40);
|
||||||
three.NextCalled.Should().BeEquivalentTo(30, 40);
|
three.NextCalled.Should().Equal(30, 40);
|
||||||
four.NextCalled.Should().BeEquivalentTo(40);
|
four.NextCalled.Should().Equal(40);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ public static class EditorRunnerChecker
|
|||||||
|
|
||||||
//var r = await UnityWebRequest.Get("https://bing.com/").SendWebRequest().ToUniTask();
|
//var r = await UnityWebRequest.Get("https://bing.com/").SendWebRequest().ToUniTask();
|
||||||
//Debug.Log(r.downloadHandler.text.Substring(0, 100));
|
//Debug.Log(r.downloadHandler.text.Substring(0, 100));
|
||||||
await UniTask.Yield();
|
//await UniTask.Yield();
|
||||||
|
|
||||||
|
await UniTask.DelayFrame(30);
|
||||||
|
|
||||||
Debug.Log("End");
|
Debug.Log("End");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,32 +4,29 @@ using System.Threading;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using Cysharp.Threading.Tasks.Triggers;
|
using Cysharp.Threading.Tasks.Triggers;
|
||||||
using System;
|
using System;
|
||||||
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
|
|
||||||
namespace Cysharp.Threading.Tasks
|
namespace Cysharp.Threading.Tasks
|
||||||
{
|
{
|
||||||
|
|
||||||
public static class CancellationTokenSourceExtensions
|
public static partial class CancellationTokenSourceExtensions
|
||||||
{
|
{
|
||||||
public static void CancelAfterSlim(this CancellationTokenSource cts, int millisecondsDelay, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
readonly static Action<object> CancelCancellationTokenSourceStateDelegate = new Action<object>(CancelCancellationTokenSourceState);
|
||||||
|
|
||||||
|
static void CancelCancellationTokenSourceState(object state)
|
||||||
{
|
{
|
||||||
var delay = UniTask.Delay(millisecondsDelay, delayType, delayTiming, cts.Token);
|
var cts = (CancellationTokenSource)state;
|
||||||
CancelAfterCore(cts, delay).Forget();
|
cts.Cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CancelAfterSlim(this CancellationTokenSource cts, TimeSpan delayTimeSpan, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
public static IDisposable CancelAfterSlim(this CancellationTokenSource cts, int millisecondsDelay, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
||||||
{
|
{
|
||||||
var delay = UniTask.Delay(delayTimeSpan, delayType, delayTiming, cts.Token);
|
return CancelAfterSlim(cts, TimeSpan.FromMilliseconds(millisecondsDelay), delayType, delayTiming);
|
||||||
CancelAfterCore(cts, delay).Forget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async UniTaskVoid CancelAfterCore(CancellationTokenSource cts, UniTask delayTask)
|
public static IDisposable CancelAfterSlim(this CancellationTokenSource cts, TimeSpan delayTimeSpan, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
||||||
{
|
{
|
||||||
var alreadyCanceled = await delayTask.SuppressCancellationThrow();
|
return PlayerLoopTimer.StartNew(delayTimeSpan, false, delayType, delayTiming, cts.Token, CancelCancellationTokenSourceStateDelegate, cts);
|
||||||
if (!alreadyCanceled)
|
|
||||||
{
|
|
||||||
cts.Cancel();
|
|
||||||
cts.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, Component component)
|
public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, Component component)
|
||||||
@@ -40,11 +37,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, GameObject gameObject)
|
public static void RegisterRaiseCancelOnDestroy(this CancellationTokenSource cts, GameObject gameObject)
|
||||||
{
|
{
|
||||||
var trigger = gameObject.GetAsyncDestroyTrigger();
|
var trigger = gameObject.GetAsyncDestroyTrigger();
|
||||||
trigger.CancellationToken.RegisterWithoutCaptureExecutionContext(state =>
|
trigger.CancellationToken.RegisterWithoutCaptureExecutionContext(CancelCancellationTokenSourceStateDelegate, cts);
|
||||||
{
|
|
||||||
var cts2 = (CancellationTokenSource)state;
|
|
||||||
cts2.Cancel();
|
|
||||||
}, cts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,12 @@
|
|||||||
"name": "com.unity.addressables",
|
"name": "com.unity.addressables",
|
||||||
"expression": "",
|
"expression": "",
|
||||||
"define": "UNITASK_ADDRESSABLE_SUPPORT"
|
"define": "UNITASK_ADDRESSABLE_SUPPORT"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "com.unity.addressables.cn",
|
||||||
|
"expression": "",
|
||||||
|
"define": "UNITASK_ADDRESSABLE_SUPPORT"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"noEngineReferences": false
|
"noEngineReferences": false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,14 +16,14 @@ namespace Cysharp.Threading.Tasks
|
|||||||
Kill,
|
Kill,
|
||||||
KillWithCompleteCallback,
|
KillWithCompleteCallback,
|
||||||
Complete,
|
Complete,
|
||||||
CompleteWithSeqeunceCallback,
|
CompleteWithSequenceCallback,
|
||||||
CancelAwait,
|
CancelAwait,
|
||||||
|
|
||||||
// AndCancelAwait
|
// AndCancelAwait
|
||||||
KillAndCancelAwait,
|
KillAndCancelAwait,
|
||||||
KillWithCompleteCallbackAndCancelAwait,
|
KillWithCompleteCallbackAndCancelAwait,
|
||||||
CompleteAndCancelAwait,
|
CompleteAndCancelAwait,
|
||||||
CompleteWithSeqeunceCallbackAndCancelAwait
|
CompleteWithSequenceCallbackAndCancelAwait
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class DOTweenAsyncExtensions
|
public static class DOTweenAsyncExtensions
|
||||||
@@ -143,8 +143,6 @@ namespace Cysharp.Threading.Tasks
|
|||||||
TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size);
|
TaskPool.RegisterSizeGetter(typeof(TweenConfiguredSource), () => pool.Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static readonly TweenCallback EmptyTweenCallback = () => { };
|
|
||||||
|
|
||||||
readonly TweenCallback onCompleteCallbackDelegate;
|
readonly TweenCallback onCompleteCallbackDelegate;
|
||||||
readonly TweenCallback onUpdateDelegate;
|
readonly TweenCallback onUpdateDelegate;
|
||||||
|
|
||||||
@@ -155,6 +153,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
bool canceled;
|
bool canceled;
|
||||||
|
|
||||||
TweenCallback originalUpdateAction;
|
TweenCallback originalUpdateAction;
|
||||||
|
TweenCallback originalCompleteAction;
|
||||||
UniTaskCompletionSourceCore<AsyncUnit> core;
|
UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||||
|
|
||||||
TweenConfiguredSource()
|
TweenConfiguredSource()
|
||||||
@@ -194,27 +193,38 @@ namespace Cysharp.Threading.Tasks
|
|||||||
switch (callbackType)
|
switch (callbackType)
|
||||||
{
|
{
|
||||||
case CallbackType.Kill:
|
case CallbackType.Kill:
|
||||||
|
result.originalCompleteAction = tween.onKill;
|
||||||
tween.onKill = result.onCompleteCallbackDelegate;
|
tween.onKill = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Complete:
|
case CallbackType.Complete:
|
||||||
|
result.originalCompleteAction = tween.onComplete;
|
||||||
tween.onComplete = result.onCompleteCallbackDelegate;
|
tween.onComplete = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Pause:
|
case CallbackType.Pause:
|
||||||
|
result.originalCompleteAction = tween.onPause;
|
||||||
tween.onPause = result.onCompleteCallbackDelegate;
|
tween.onPause = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Play:
|
case CallbackType.Play:
|
||||||
|
result.originalCompleteAction = tween.onPlay;
|
||||||
tween.onPlay = result.onCompleteCallbackDelegate;
|
tween.onPlay = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Rewind:
|
case CallbackType.Rewind:
|
||||||
|
result.originalCompleteAction = tween.onRewind;
|
||||||
tween.onRewind = result.onCompleteCallbackDelegate;
|
tween.onRewind = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
case CallbackType.StepComplete:
|
case CallbackType.StepComplete:
|
||||||
|
result.originalCompleteAction = tween.onStepComplete;
|
||||||
tween.onStepComplete = result.onCompleteCallbackDelegate;
|
tween.onStepComplete = result.onCompleteCallbackDelegate;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.originalCompleteAction == result.onCompleteCallbackDelegate)
|
||||||
|
{
|
||||||
|
result.originalCompleteAction = null;
|
||||||
|
}
|
||||||
|
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
token = result.core.Version;
|
token = result.core.Version;
|
||||||
@@ -228,7 +238,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|
if (this.cancelBehaviour == TweenCancelBehaviour.KillAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait
|
|| this.cancelBehaviour == TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait
|
||||||
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
|| this.cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
||||||
{
|
{
|
||||||
canceled = true;
|
canceled = true;
|
||||||
@@ -240,6 +250,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
originalCompleteAction?.Invoke();
|
||||||
core.TrySetResult(AsyncUnit.Default);
|
core.TrySetResult(AsyncUnit.Default);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -277,34 +288,34 @@ namespace Cysharp.Threading.Tasks
|
|||||||
this.canceled = true;
|
this.canceled = true;
|
||||||
this.tween.Complete(false);
|
this.tween.Complete(false);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallback:
|
case TweenCancelBehaviour.CompleteWithSequenceCallback:
|
||||||
this.tween.Complete(true);
|
this.tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait:
|
case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait:
|
||||||
this.canceled = true;
|
this.canceled = true;
|
||||||
this.tween.Complete(true);
|
this.tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CancelAwait:
|
case TweenCancelBehaviour.CancelAwait:
|
||||||
// replace to empty(avoid callback after Canceled(instance is returned to pool.)
|
// restore to original callback
|
||||||
switch (callbackType)
|
switch (callbackType)
|
||||||
{
|
{
|
||||||
case CallbackType.Kill:
|
case CallbackType.Kill:
|
||||||
tween.onKill = EmptyTweenCallback;
|
tween.onKill = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Complete:
|
case CallbackType.Complete:
|
||||||
tween.onComplete = EmptyTweenCallback;
|
tween.onComplete = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Pause:
|
case CallbackType.Pause:
|
||||||
tween.onPause = EmptyTweenCallback;
|
tween.onPause = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Play:
|
case CallbackType.Play:
|
||||||
tween.onPlay = EmptyTweenCallback;
|
tween.onPlay = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Rewind:
|
case CallbackType.Rewind:
|
||||||
tween.onRewind = EmptyTweenCallback;
|
tween.onRewind = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.StepComplete:
|
case CallbackType.StepComplete:
|
||||||
tween.onStepComplete = EmptyTweenCallback;
|
tween.onStepComplete = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -339,10 +350,10 @@ namespace Cysharp.Threading.Tasks
|
|||||||
case TweenCancelBehaviour.CompleteAndCancelAwait:
|
case TweenCancelBehaviour.CompleteAndCancelAwait:
|
||||||
tween.Complete(false);
|
tween.Complete(false);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallback:
|
case TweenCancelBehaviour.CompleteWithSequenceCallback:
|
||||||
tween.Complete(true);
|
tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait:
|
case TweenCancelBehaviour.CompleteWithSequenceCallbackAndCancelAwait:
|
||||||
tween.Complete(true);
|
tween.Complete(true);
|
||||||
break;
|
break;
|
||||||
case TweenCancelBehaviour.CancelAwait:
|
case TweenCancelBehaviour.CancelAwait:
|
||||||
@@ -386,22 +397,22 @@ namespace Cysharp.Threading.Tasks
|
|||||||
switch (callbackType)
|
switch (callbackType)
|
||||||
{
|
{
|
||||||
case CallbackType.Kill:
|
case CallbackType.Kill:
|
||||||
tween.onKill = null;
|
tween.onKill = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Complete:
|
case CallbackType.Complete:
|
||||||
tween.onComplete = null;
|
tween.onComplete = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Pause:
|
case CallbackType.Pause:
|
||||||
tween.onPause = null;
|
tween.onPause = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Play:
|
case CallbackType.Play:
|
||||||
tween.onPlay = null;
|
tween.onPlay = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.Rewind:
|
case CallbackType.Rewind:
|
||||||
tween.onRewind = null;
|
tween.onRewind = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
case CallbackType.StepComplete:
|
case CallbackType.StepComplete:
|
||||||
tween.onStepComplete = null;
|
tween.onStepComplete = originalCompleteAction;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -410,6 +421,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
tween = default;
|
tween = default;
|
||||||
cancellationToken = default;
|
cancellationToken = default;
|
||||||
originalUpdateAction = default;
|
originalUpdateAction = default;
|
||||||
|
originalCompleteAction = default;
|
||||||
return pool.TryPush(this);
|
return pool.TryPush(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ namespace Cysharp.Threading.Tasks.Internal
|
|||||||
|
|
||||||
foreach (var candidateMethod in methods)
|
foreach (var candidateMethod in methods)
|
||||||
{
|
{
|
||||||
var attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>();
|
var attributes = candidateMethod.GetCustomAttributes<StateMachineAttribute>(false);
|
||||||
if (attributes == null)
|
if (attributes == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
{
|
{
|
||||||
Error.ThrowArgumentNullException(source, nameof(source));
|
Error.ThrowArgumentNullException(source, nameof(source));
|
||||||
|
|
||||||
return new AppendPrepend<TSource>(source, element, true);
|
return new AppendPrepend<TSource>(source, element, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
|||||||
|
|
||||||
if (enumerator == null)
|
if (enumerator == null)
|
||||||
{
|
{
|
||||||
if (state == State.RequireAppend)
|
if (state == State.RequirePrepend)
|
||||||
{
|
{
|
||||||
Current = element;
|
Current = element;
|
||||||
state = State.None;
|
state = State.None;
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
static readonly ContinuationQueue ThrowMarkerContinuationQueue = new ContinuationQueue(PlayerLoopTiming.Initialization);
|
static readonly ContinuationQueue ThrowMarkerContinuationQueue = new ContinuationQueue(PlayerLoopTiming.Initialization);
|
||||||
static readonly PlayerLoopRunner ThrowMarkerPlayerLoopRunner = new PlayerLoopRunner(PlayerLoopTiming.Initialization);
|
static readonly PlayerLoopRunner ThrowMarkerPlayerLoopRunner = new PlayerLoopRunner(PlayerLoopTiming.Initialization);
|
||||||
|
|
||||||
public static SynchronizationContext UnitySynchronizationContext => unitySynchronizationContetext;
|
public static SynchronizationContext UnitySynchronizationContext => unitySynchronizationContext;
|
||||||
public static int MainThreadId => mainThreadId;
|
public static int MainThreadId => mainThreadId;
|
||||||
internal static string ApplicationDataPath => applicationDataPath;
|
internal static string ApplicationDataPath => applicationDataPath;
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
static int mainThreadId;
|
static int mainThreadId;
|
||||||
static string applicationDataPath;
|
static string applicationDataPath;
|
||||||
static SynchronizationContext unitySynchronizationContetext;
|
static SynchronizationContext unitySynchronizationContext;
|
||||||
static ContinuationQueue[] yielders;
|
static ContinuationQueue[] yielders;
|
||||||
static PlayerLoopRunner[] runners;
|
static PlayerLoopRunner[] runners;
|
||||||
internal static bool IsEditorApplicationQuitting { get; private set; }
|
internal static bool IsEditorApplicationQuitting { get; private set; }
|
||||||
@@ -289,7 +289,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
static void Init()
|
static void Init()
|
||||||
{
|
{
|
||||||
// capture default(unity) sync-context.
|
// capture default(unity) sync-context.
|
||||||
unitySynchronizationContetext = SynchronizationContext.Current;
|
unitySynchronizationContext = SynchronizationContext.Current;
|
||||||
mainThreadId = Thread.CurrentThread.ManagedThreadId;
|
mainThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -524,6 +524,14 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
sb.AppendFormat("------{0}------", header.type.Name);
|
sb.AppendFormat("------{0}------", header.type.Name);
|
||||||
sb.AppendLine();
|
sb.AppendLine();
|
||||||
|
|
||||||
|
if (header.subSystemList is null)
|
||||||
|
{
|
||||||
|
sb.AppendFormat("{0} has no subsystems!", header.ToString());
|
||||||
|
sb.AppendLine();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var subSystem in header.subSystemList)
|
foreach (var subSystem in header.subSystemList)
|
||||||
{
|
{
|
||||||
sb.AppendFormat("{0}", subSystem.type.Name);
|
sb.AppendFormat("{0}", subSystem.type.Name);
|
||||||
@@ -545,6 +553,11 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
foreach (var header in playerLoop.subSystemList)
|
foreach (var header in playerLoop.subSystemList)
|
||||||
{
|
{
|
||||||
|
if (header.subSystemList is null)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var subSystem in header.subSystemList)
|
foreach (var subSystem in header.subSystemList)
|
||||||
{
|
{
|
||||||
if (subSystem.type == typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization))
|
if (subSystem.type == typeof(UniTaskLoopRunners.UniTaskLoopRunnerInitialization))
|
||||||
|
|||||||
262
src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopTimer.cs
Normal file
262
src/UniTask/Assets/Plugins/UniTask/Runtime/PlayerLoopTimer.cs
Normal file
@@ -0,0 +1,262 @@
|
|||||||
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||||
|
|
||||||
|
using System.Threading;
|
||||||
|
using System;
|
||||||
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.Tasks
|
||||||
|
{
|
||||||
|
public abstract class PlayerLoopTimer : IDisposable, IPlayerLoopItem
|
||||||
|
{
|
||||||
|
readonly CancellationToken cancellationToken;
|
||||||
|
readonly Action<object> timerCallback;
|
||||||
|
readonly object state;
|
||||||
|
readonly PlayerLoopTiming playerLoopTiming;
|
||||||
|
readonly bool periodic;
|
||||||
|
|
||||||
|
bool isRunning;
|
||||||
|
bool tryStop;
|
||||||
|
bool isDisposed;
|
||||||
|
|
||||||
|
protected PlayerLoopTimer(bool periodic, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
{
|
||||||
|
this.periodic = periodic;
|
||||||
|
this.playerLoopTiming = playerLoopTiming;
|
||||||
|
this.cancellationToken = cancellationToken;
|
||||||
|
this.timerCallback = timerCallback;
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerLoopTimer Create(TimeSpan interval, bool periodic, DelayType delayType, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
// force use Realtime.
|
||||||
|
if (PlayerLoopHelper.IsMainThread && !UnityEditor.EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
delayType = DelayType.Realtime;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (delayType)
|
||||||
|
{
|
||||||
|
case DelayType.UnscaledDeltaTime:
|
||||||
|
return new IgnoreTimeScalePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state);
|
||||||
|
case DelayType.Realtime:
|
||||||
|
return new RealtimePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state);
|
||||||
|
case DelayType.DeltaTime:
|
||||||
|
default:
|
||||||
|
return new DeltaTimePlayerLoopTimer(interval, periodic, playerLoopTiming, cancellationToken, timerCallback, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayerLoopTimer StartNew(TimeSpan interval, bool periodic, DelayType delayType, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
{
|
||||||
|
var timer = Create(interval, periodic, delayType, playerLoopTiming, cancellationToken, timerCallback, state);
|
||||||
|
timer.Restart();
|
||||||
|
return timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restart(Reset and Start) timer.
|
||||||
|
/// </summary>
|
||||||
|
public void Restart()
|
||||||
|
{
|
||||||
|
if (isDisposed) throw new ObjectDisposedException(null);
|
||||||
|
|
||||||
|
ResetCore(null); // init state
|
||||||
|
if (!isRunning)
|
||||||
|
{
|
||||||
|
isRunning = true;
|
||||||
|
PlayerLoopHelper.AddAction(playerLoopTiming, this);
|
||||||
|
}
|
||||||
|
tryStop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restart(Reset and Start) and change interval.
|
||||||
|
/// </summary>
|
||||||
|
public void Restart(TimeSpan interval)
|
||||||
|
{
|
||||||
|
if (isDisposed) throw new ObjectDisposedException(null);
|
||||||
|
|
||||||
|
ResetCore(interval); // init state
|
||||||
|
if (!isRunning)
|
||||||
|
{
|
||||||
|
isRunning = true;
|
||||||
|
PlayerLoopHelper.AddAction(playerLoopTiming, this);
|
||||||
|
}
|
||||||
|
tryStop = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stop timer.
|
||||||
|
/// </summary>
|
||||||
|
public void Stop()
|
||||||
|
{
|
||||||
|
tryStop = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void ResetCore(TimeSpan? newInterval);
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
isDisposed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IPlayerLoopItem.MoveNext()
|
||||||
|
{
|
||||||
|
if (isDisposed)
|
||||||
|
{
|
||||||
|
isRunning = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (tryStop)
|
||||||
|
{
|
||||||
|
isRunning = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
isRunning = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!MoveNextCore())
|
||||||
|
{
|
||||||
|
timerCallback(state);
|
||||||
|
|
||||||
|
if (periodic)
|
||||||
|
{
|
||||||
|
ResetCore(null);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isRunning = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract bool MoveNextCore();
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class DeltaTimePlayerLoopTimer : PlayerLoopTimer
|
||||||
|
{
|
||||||
|
int initialFrame;
|
||||||
|
float elapsed;
|
||||||
|
float interval;
|
||||||
|
|
||||||
|
public DeltaTimePlayerLoopTimer(TimeSpan interval, bool periodic, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
: base(periodic, playerLoopTiming, cancellationToken, timerCallback, state)
|
||||||
|
{
|
||||||
|
ResetCore(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool MoveNextCore()
|
||||||
|
{
|
||||||
|
if (elapsed == 0.0f)
|
||||||
|
{
|
||||||
|
if (initialFrame == Time.frameCount)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed += Time.deltaTime;
|
||||||
|
if (elapsed >= interval)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ResetCore(TimeSpan? interval)
|
||||||
|
{
|
||||||
|
this.elapsed = 0.0f;
|
||||||
|
this.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
|
||||||
|
if (interval != null)
|
||||||
|
{
|
||||||
|
this.interval = (float)interval.Value.TotalSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class IgnoreTimeScalePlayerLoopTimer : PlayerLoopTimer
|
||||||
|
{
|
||||||
|
int initialFrame;
|
||||||
|
float elapsed;
|
||||||
|
float interval;
|
||||||
|
|
||||||
|
public IgnoreTimeScalePlayerLoopTimer(TimeSpan interval, bool periodic, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
: base(periodic, playerLoopTiming, cancellationToken, timerCallback, state)
|
||||||
|
{
|
||||||
|
ResetCore(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool MoveNextCore()
|
||||||
|
{
|
||||||
|
if (elapsed == 0.0f)
|
||||||
|
{
|
||||||
|
if (initialFrame == Time.frameCount)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elapsed += Time.unscaledDeltaTime;
|
||||||
|
if (elapsed >= interval)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ResetCore(TimeSpan? interval)
|
||||||
|
{
|
||||||
|
this.elapsed = 0.0f;
|
||||||
|
this.initialFrame = PlayerLoopHelper.IsMainThread ? Time.frameCount : -1;
|
||||||
|
if (interval != null)
|
||||||
|
{
|
||||||
|
this.interval = (float)interval.Value.TotalSeconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class RealtimePlayerLoopTimer : PlayerLoopTimer
|
||||||
|
{
|
||||||
|
ValueStopwatch stopwatch;
|
||||||
|
long intervalTicks;
|
||||||
|
|
||||||
|
public RealtimePlayerLoopTimer(TimeSpan interval, bool periodic, PlayerLoopTiming playerLoopTiming, CancellationToken cancellationToken, Action<object> timerCallback, object state)
|
||||||
|
: base(periodic, playerLoopTiming, cancellationToken, timerCallback, state)
|
||||||
|
{
|
||||||
|
ResetCore(interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool MoveNextCore()
|
||||||
|
{
|
||||||
|
if (stopwatch.ElapsedTicks >= intervalTicks)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void ResetCore(TimeSpan? interval)
|
||||||
|
{
|
||||||
|
this.stopwatch = ValueStopwatch.StartNew();
|
||||||
|
if (interval != null)
|
||||||
|
{
|
||||||
|
this.intervalTicks = interval.Value.Ticks;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 57095a17fdca7ee4380450910afc7f26
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -7,7 +7,7 @@ using System.Threading;
|
|||||||
|
|
||||||
namespace Cysharp.Threading.Tasks
|
namespace Cysharp.Threading.Tasks
|
||||||
{
|
{
|
||||||
// internaly used but public, allow to user create custom operator with pooling.
|
// internally used but public, allow to user create custom operator with pooling.
|
||||||
|
|
||||||
public static class TaskPool
|
public static class TaskPool
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
#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
|
||||||
|
|
||||||
using System.Threading;
|
|
||||||
using System;
|
using System;
|
||||||
using Cysharp.Threading.Tasks.Internal;
|
using System.Threading;
|
||||||
|
|
||||||
namespace Cysharp.Threading.Tasks
|
namespace Cysharp.Threading.Tasks
|
||||||
{
|
{
|
||||||
@@ -14,26 +13,44 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
public sealed class TimeoutController : IDisposable
|
public sealed class TimeoutController : IDisposable
|
||||||
{
|
{
|
||||||
|
readonly static Action<object> CancelCancellationTokenSourceStateDelegate = new Action<object>(CancelCancellationTokenSourceState);
|
||||||
|
|
||||||
|
static void CancelCancellationTokenSourceState(object state)
|
||||||
|
{
|
||||||
|
var cts = (CancellationTokenSource)state;
|
||||||
|
cts.Cancel();
|
||||||
|
}
|
||||||
|
|
||||||
CancellationTokenSource timeoutSource;
|
CancellationTokenSource timeoutSource;
|
||||||
CancellationTokenSource linkedSource;
|
CancellationTokenSource linkedSource;
|
||||||
StoppableDelayRealtimePromise timeoutDelay;
|
PlayerLoopTimer timer;
|
||||||
|
bool isDisposed;
|
||||||
|
|
||||||
|
readonly DelayType delayType;
|
||||||
|
readonly PlayerLoopTiming delayTiming;
|
||||||
readonly CancellationTokenSource originalLinkCancellationTokenSource;
|
readonly CancellationTokenSource originalLinkCancellationTokenSource;
|
||||||
|
|
||||||
public TimeoutController()
|
public TimeoutController(DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
||||||
{
|
{
|
||||||
this.timeoutSource = new CancellationTokenSource();
|
this.timeoutSource = new CancellationTokenSource();
|
||||||
this.originalLinkCancellationTokenSource = null;
|
this.originalLinkCancellationTokenSource = null;
|
||||||
this.linkedSource = null;
|
this.linkedSource = null;
|
||||||
this.timeoutDelay = null;
|
this.delayType = delayType;
|
||||||
|
this.delayTiming = delayTiming;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeoutController(CancellationTokenSource linkCancellationTokenSource)
|
public TimeoutController(CancellationTokenSource linkCancellationTokenSource, DelayType delayType = DelayType.DeltaTime, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update)
|
||||||
{
|
{
|
||||||
this.timeoutSource = new CancellationTokenSource();
|
this.timeoutSource = new CancellationTokenSource();
|
||||||
this.originalLinkCancellationTokenSource = linkCancellationTokenSource;
|
this.originalLinkCancellationTokenSource = linkCancellationTokenSource;
|
||||||
this.linkedSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, linkCancellationTokenSource.Token);
|
this.linkedSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, linkCancellationTokenSource.Token);
|
||||||
this.timeoutDelay = null;
|
this.delayType = delayType;
|
||||||
|
this.delayTiming = delayTiming;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CancellationToken Timeout(int millisecondsTimeout)
|
||||||
|
{
|
||||||
|
return Timeout(TimeSpan.FromMilliseconds(millisecondsTimeout));
|
||||||
}
|
}
|
||||||
|
|
||||||
public CancellationToken Timeout(TimeSpan timeout)
|
public CancellationToken Timeout(TimeSpan timeout)
|
||||||
@@ -43,6 +60,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return originalLinkCancellationTokenSource.Token;
|
return originalLinkCancellationTokenSource.Token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Timeouted, create new source and timer.
|
||||||
if (timeoutSource.IsCancellationRequested)
|
if (timeoutSource.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
timeoutSource.Dispose();
|
timeoutSource.Dispose();
|
||||||
@@ -53,18 +71,25 @@ namespace Cysharp.Threading.Tasks
|
|||||||
this.linkedSource.Dispose();
|
this.linkedSource.Dispose();
|
||||||
this.linkedSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, originalLinkCancellationTokenSource.Token);
|
this.linkedSource = CancellationTokenSource.CreateLinkedTokenSource(timeoutSource.Token, originalLinkCancellationTokenSource.Token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timer?.Dispose();
|
||||||
|
timer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (timeoutDelay == null)
|
var useSource = (linkedSource != null) ? linkedSource : timeoutSource;
|
||||||
|
var token = useSource.Token;
|
||||||
|
if (timer == null)
|
||||||
{
|
{
|
||||||
RunDelayAsync(timeout).Forget(); // timeoutDelay = ... in RunDelayAsync(immediately, before await)
|
// Timer complete => timeoutSource.Cancel() -> linkedSource will be canceled.
|
||||||
|
// (linked)token is canceled => stop timer
|
||||||
|
timer = PlayerLoopTimer.StartNew(timeout, false, delayType, delayTiming, token, CancelCancellationTokenSourceStateDelegate, timeoutSource);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
timeoutDelay.RestartStopwatch(); // already running RunDelayAsync
|
timer.Restart(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (linkedSource != null) ? linkedSource.Token : timeoutSource.Token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsTimeout()
|
public bool IsTimeout()
|
||||||
@@ -74,184 +99,30 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
public void Reset()
|
public void Reset()
|
||||||
{
|
{
|
||||||
if (timeoutDelay != null)
|
timer?.Stop();
|
||||||
{
|
|
||||||
timeoutDelay.Stop(); // stop delay, will finish RunDelayAsync
|
|
||||||
timeoutDelay = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async UniTaskVoid RunDelayAsync(TimeSpan timeout)
|
|
||||||
{
|
|
||||||
timeoutDelay = StoppableDelayRealtimePromise.Create(timeout, PlayerLoopTiming.Update, (linkedSource == null) ? CancellationToken.None : linkedSource.Token, out var version);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var reason = await new UniTask<DelayResult>(timeoutDelay, version);
|
|
||||||
if (reason == DelayResult.DelayCompleted)
|
|
||||||
{
|
|
||||||
// UnityEngine.Debug.Log("DEBUG:Timeout Complete, try to call timeoutSource.Cancel");
|
|
||||||
timeoutSource.Cancel();
|
|
||||||
}
|
|
||||||
else if (reason == DelayResult.LinkedTokenCanceled)
|
|
||||||
{
|
|
||||||
// UnityEngine.Debug.Log("DEBUG:LinkedSource IsCancellationRequested");
|
|
||||||
}
|
|
||||||
else if (reason == DelayResult.ExternalStopped)
|
|
||||||
{
|
|
||||||
// Reset(Promise.Stop) called, do nothing.
|
|
||||||
// UnityEngine.Debug.Log("DEBUG:Reset called");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
timeoutDelay = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
if (timeoutDelay != null)
|
if (isDisposed) return;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
timeoutDelay.Stop();
|
// stop timer.
|
||||||
}
|
timer?.Dispose();
|
||||||
timeoutSource.Dispose();
|
|
||||||
if (linkedSource != null)
|
|
||||||
{
|
|
||||||
linkedSource.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
enum DelayResult
|
// cancel and dispose.
|
||||||
{
|
timeoutSource.Cancel();
|
||||||
LinkedTokenCanceled,
|
timeoutSource.Dispose();
|
||||||
ExternalStopped,
|
if (linkedSource != null)
|
||||||
DelayCompleted, // as Timeout.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Stop + SuppressCancellationThrow.
|
|
||||||
sealed class StoppableDelayRealtimePromise : IUniTaskSource<DelayResult>, IPlayerLoopItem, ITaskPoolNode<StoppableDelayRealtimePromise>
|
|
||||||
{
|
|
||||||
static OperationCanceledException ExterenalStopException = new OperationCanceledException();
|
|
||||||
|
|
||||||
static TaskPool<StoppableDelayRealtimePromise> pool;
|
|
||||||
StoppableDelayRealtimePromise nextNode;
|
|
||||||
public ref StoppableDelayRealtimePromise NextNode => ref nextNode;
|
|
||||||
|
|
||||||
static StoppableDelayRealtimePromise()
|
|
||||||
{
|
|
||||||
TaskPool.RegisterSizeGetter(typeof(StoppableDelayRealtimePromise), () => pool.Size);
|
|
||||||
}
|
|
||||||
|
|
||||||
long delayTimeSpanTicks;
|
|
||||||
ValueStopwatch stopwatch;
|
|
||||||
CancellationToken cancellationToken;
|
|
||||||
bool externalStop;
|
|
||||||
|
|
||||||
UniTaskCompletionSourceCore<DelayResult> core;
|
|
||||||
|
|
||||||
StoppableDelayRealtimePromise()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static StoppableDelayRealtimePromise Create(TimeSpan delayTimeSpan, PlayerLoopTiming timing, CancellationToken cancellationToken, out short token)
|
|
||||||
{
|
|
||||||
if (!pool.TryPop(out var result))
|
|
||||||
{
|
{
|
||||||
result = new StoppableDelayRealtimePromise();
|
linkedSource.Cancel();
|
||||||
}
|
linkedSource.Dispose();
|
||||||
|
|
||||||
result.stopwatch = ValueStopwatch.StartNew();
|
|
||||||
result.delayTimeSpanTicks = delayTimeSpan.Ticks;
|
|
||||||
result.cancellationToken = cancellationToken;
|
|
||||||
result.externalStop = false;
|
|
||||||
|
|
||||||
TaskTracker.TrackActiveTask(result, 3);
|
|
||||||
|
|
||||||
PlayerLoopHelper.AddAction(timing, result);
|
|
||||||
|
|
||||||
token = result.core.Version;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Stop()
|
|
||||||
{
|
|
||||||
externalStop = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RestartStopwatch()
|
|
||||||
{
|
|
||||||
stopwatch = ValueStopwatch.StartNew();
|
|
||||||
}
|
|
||||||
|
|
||||||
public DelayResult GetResult(short token)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return core.GetResult(token);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
TryReturn();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
void IUniTaskSource.GetResult(short token)
|
|
||||||
{
|
{
|
||||||
GetResult(token);
|
isDisposed = true;
|
||||||
}
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
if (cancellationToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
core.TrySetResult(DelayResult.LinkedTokenCanceled);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (externalStop)
|
|
||||||
{
|
|
||||||
core.TrySetResult(DelayResult.ExternalStopped);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stopwatch.IsInvalid)
|
|
||||||
{
|
|
||||||
core.TrySetResult(DelayResult.DelayCompleted);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (stopwatch.ElapsedTicks >= delayTimeSpanTicks)
|
|
||||||
{
|
|
||||||
core.TrySetResult(DelayResult.DelayCompleted);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryReturn()
|
|
||||||
{
|
|
||||||
TaskTracker.RemoveTracking(this);
|
|
||||||
core.Reset();
|
|
||||||
stopwatch = default;
|
|
||||||
cancellationToken = default;
|
|
||||||
externalStop = false;
|
|
||||||
return pool.TryPush(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,16 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
public static class UniTaskCancellationExtensions
|
public static class UniTaskCancellationExtensions
|
||||||
{
|
{
|
||||||
|
#if UNITY_2022_2_OR_NEWER
|
||||||
|
|
||||||
|
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
||||||
|
public static CancellationToken GetCancellationTokenOnDestroy(this MonoBehaviour monoBehaviour)
|
||||||
|
{
|
||||||
|
return monoBehaviour.destroyCancellationToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
||||||
public static CancellationToken GetCancellationTokenOnDestroy(this GameObject gameObject)
|
public static CancellationToken GetCancellationTokenOnDestroy(this GameObject gameObject)
|
||||||
{
|
{
|
||||||
@@ -17,6 +27,13 @@ namespace Cysharp.Threading.Tasks
|
|||||||
/// <summary>This CancellationToken is canceled when the MonoBehaviour will be destroyed.</summary>
|
/// <summary>This CancellationToken is canceled when the MonoBehaviour 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 (component is MonoBehaviour mb)
|
||||||
|
{
|
||||||
|
return mb.destroyCancellationToken;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return component.GetAsyncDestroyTrigger().CancellationToken;
|
return component.GetAsyncDestroyTrigger().CancellationToken;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
using Cysharp.Threading.Tasks.Internal;
|
using Cysharp.Threading.Tasks.Internal;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -74,37 +75,40 @@ namespace Cysharp.Threading.Tasks
|
|||||||
return new UniTask(NextFramePromise.Create(timing, cancellationToken, out var token), token);
|
return new UniTask(NextFramePromise.Create(timing, cancellationToken, out var token), token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Obsolete("Use WaitForEndOfFrame(MonoBehaviour) instead or UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate). Equivalent for coroutine's WaitForEndOfFrame requires MonoBehaviour(runner of Coroutine).")]
|
||||||
/// <summary>
|
|
||||||
/// Same as UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate).
|
|
||||||
/// </summary>
|
|
||||||
public static YieldAwaitable WaitForEndOfFrame()
|
public static YieldAwaitable WaitForEndOfFrame()
|
||||||
{
|
{
|
||||||
return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate);
|
return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
[Obsolete("Use WaitForEndOfFrame(MonoBehaviour) instead or UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate). Equivalent for coroutine's WaitForEndOfFrame requires MonoBehaviour(runner of Coroutine).")]
|
||||||
/// Same as UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken).
|
|
||||||
/// </summary>
|
|
||||||
public static UniTask WaitForEndOfFrame(CancellationToken cancellationToken)
|
public static UniTask WaitForEndOfFrame(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken);
|
return UniTask.Yield(PlayerLoopTiming.LastPostLateUpdate, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
public static UniTask WaitForEndOfFrame(MonoBehaviour coroutineRunner, CancellationToken cancellationToken = default)
|
||||||
/// Same as UniTask.Yield(PlayerLoopTiming.FixedUpdate).
|
|
||||||
/// </summary>
|
|
||||||
public static YieldAwaitable WaitForFixedUpdate()
|
|
||||||
{
|
{
|
||||||
return UniTask.Yield(PlayerLoopTiming.FixedUpdate);
|
var source = WaitForEndOfFramePromise.Create(coroutineRunner, cancellationToken, out var token);
|
||||||
|
return new UniTask(source, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Same as UniTask.Yield(PlayerLoopTiming.FixedUpdate, cancellationToken).
|
/// Same as UniTask.Yield(PlayerLoopTiming.LastFixedUpdate).
|
||||||
|
/// </summary>
|
||||||
|
public static YieldAwaitable WaitForFixedUpdate()
|
||||||
|
{
|
||||||
|
// use LastFixedUpdate instead of FixedUpdate
|
||||||
|
// https://github.com/Cysharp/UniTask/issues/377
|
||||||
|
return UniTask.Yield(PlayerLoopTiming.LastFixedUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Same as UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken)
|
public static UniTask WaitForFixedUpdate(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return UniTask.Yield(PlayerLoopTiming.FixedUpdate, cancellationToken);
|
return UniTask.Yield(PlayerLoopTiming.LastFixedUpdate, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
public static UniTask DelayFrame(int delayFrameCount, PlayerLoopTiming delayTiming = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
@@ -352,6 +356,113 @@ namespace Cysharp.Threading.Tasks
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sealed class WaitForEndOfFramePromise : IUniTaskSource, ITaskPoolNode<WaitForEndOfFramePromise>, System.Collections.IEnumerator
|
||||||
|
{
|
||||||
|
static TaskPool<WaitForEndOfFramePromise> pool;
|
||||||
|
WaitForEndOfFramePromise nextNode;
|
||||||
|
public ref WaitForEndOfFramePromise NextNode => ref nextNode;
|
||||||
|
|
||||||
|
static WaitForEndOfFramePromise()
|
||||||
|
{
|
||||||
|
TaskPool.RegisterSizeGetter(typeof(WaitForEndOfFramePromise), () => pool.Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
CancellationToken cancellationToken;
|
||||||
|
UniTaskCompletionSourceCore<object> core;
|
||||||
|
|
||||||
|
WaitForEndOfFramePromise()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IUniTaskSource Create(MonoBehaviour coroutineRunner, CancellationToken cancellationToken, out short token)
|
||||||
|
{
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!pool.TryPop(out var result))
|
||||||
|
{
|
||||||
|
result = new WaitForEndOfFramePromise();
|
||||||
|
}
|
||||||
|
|
||||||
|
result.cancellationToken = cancellationToken;
|
||||||
|
|
||||||
|
TaskTracker.TrackActiveTask(result, 3);
|
||||||
|
|
||||||
|
coroutineRunner.StartCoroutine(result);
|
||||||
|
|
||||||
|
token = result.core.Version;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void GetResult(short token)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
core.GetResult(token);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
TryReturn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TryReturn()
|
||||||
|
{
|
||||||
|
TaskTracker.RemoveTracking(this);
|
||||||
|
core.Reset();
|
||||||
|
Reset(); // Reset Enumerator
|
||||||
|
cancellationToken = default;
|
||||||
|
return pool.TryPush(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Coroutine Runner implementation
|
||||||
|
|
||||||
|
static readonly WaitForEndOfFrame waitForEndOfFrameYieldInstruction = new WaitForEndOfFrame();
|
||||||
|
bool isFirst = true;
|
||||||
|
|
||||||
|
object IEnumerator.Current => waitForEndOfFrameYieldInstruction;
|
||||||
|
|
||||||
|
bool IEnumerator.MoveNext()
|
||||||
|
{
|
||||||
|
if (isFirst)
|
||||||
|
{
|
||||||
|
isFirst = false;
|
||||||
|
return true; // start WaitForEndOfFrame
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
core.TrySetCanceled(cancellationToken);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
core.TrySetResult(null);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset()
|
||||||
|
{
|
||||||
|
isFirst = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayFramePromise>
|
sealed class DelayFramePromise : IUniTaskSource, IPlayerLoopItem, ITaskPoolNode<DelayFramePromise>
|
||||||
{
|
{
|
||||||
static TaskPool<DelayFramePromise> pool;
|
static TaskPool<DelayFramePromise> pool;
|
||||||
@@ -444,7 +555,19 @@ namespace Cysharp.Threading.Tasks
|
|||||||
// skip in initial frame.
|
// skip in initial frame.
|
||||||
if (initialFrame == Time.frameCount)
|
if (initialFrame == Time.frameCount)
|
||||||
{
|
{
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
// force use Realtime.
|
||||||
|
if (PlayerLoopHelper.IsMainThread && !UnityEditor.EditorApplication.isPlaying)
|
||||||
|
{
|
||||||
|
//goto ++currentFrameCount
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#else
|
||||||
return true;
|
return true;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -194,6 +194,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
sealed class ExceptionResultSource : IUniTaskSource
|
sealed class ExceptionResultSource : IUniTaskSource
|
||||||
{
|
{
|
||||||
readonly ExceptionDispatchInfo exception;
|
readonly ExceptionDispatchInfo exception;
|
||||||
|
bool calledGet;
|
||||||
|
|
||||||
public ExceptionResultSource(Exception exception)
|
public ExceptionResultSource(Exception exception)
|
||||||
{
|
{
|
||||||
@@ -202,6 +203,11 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
public void GetResult(short token)
|
public void GetResult(short token)
|
||||||
{
|
{
|
||||||
|
if (!calledGet)
|
||||||
|
{
|
||||||
|
calledGet = true;
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
exception.Throw();
|
exception.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,11 +225,20 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
continuation(state);
|
continuation(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ExceptionResultSource()
|
||||||
|
{
|
||||||
|
if (!calledGet)
|
||||||
|
{
|
||||||
|
UniTaskScheduler.PublishUnobservedTaskException(exception.SourceException);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class ExceptionResultSource<T> : IUniTaskSource<T>
|
sealed class ExceptionResultSource<T> : IUniTaskSource<T>
|
||||||
{
|
{
|
||||||
readonly ExceptionDispatchInfo exception;
|
readonly ExceptionDispatchInfo exception;
|
||||||
|
bool calledGet;
|
||||||
|
|
||||||
public ExceptionResultSource(Exception exception)
|
public ExceptionResultSource(Exception exception)
|
||||||
{
|
{
|
||||||
@@ -232,12 +247,22 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
public T GetResult(short token)
|
public T GetResult(short token)
|
||||||
{
|
{
|
||||||
|
if (!calledGet)
|
||||||
|
{
|
||||||
|
calledGet = true;
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
exception.Throw();
|
exception.Throw();
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
|
|
||||||
void IUniTaskSource.GetResult(short token)
|
void IUniTaskSource.GetResult(short token)
|
||||||
{
|
{
|
||||||
|
if (!calledGet)
|
||||||
|
{
|
||||||
|
calledGet = true;
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
exception.Throw();
|
exception.Throw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,6 +280,14 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
continuation(state);
|
continuation(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~ExceptionResultSource()
|
||||||
|
{
|
||||||
|
if (!calledGet)
|
||||||
|
{
|
||||||
|
UniTaskScheduler.PublishUnobservedTaskException(exception.SourceException);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class CanceledResultSource : IUniTaskSource
|
sealed class CanceledResultSource : IUniTaskSource
|
||||||
|
|||||||
@@ -9,237 +9,56 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
#region OBSOLETE_RUN
|
#region OBSOLETE_RUN
|
||||||
|
|
||||||
// Run is a confusing name, use only RunOnThreadPool in the future.
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
|
public static UniTask Run(Action action, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
/// <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)
|
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(action, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
action();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
action();
|
|
||||||
}
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask Run(Action<object> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask Run(Action<object> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(action, state, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
action(state);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
action(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask Run(Func<UniTask> action, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask Run(Func<UniTask> action, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(action, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await action();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await action();
|
|
||||||
}
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask Run(Func<object, UniTask> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask Run(Func<object, UniTask> action, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(action, state, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
await action(state);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await action(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask<T> Run<T>(Func<T> func, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask<T> Run<T>(Func<T> func, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(func, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return func();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return func();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask<T> Run<T>(Func<UniTask<T>> func, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask<T> Run<T>(Func<UniTask<T>> func, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(func, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await func();
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
await UniTask.Yield();
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var result = await func();
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask<T> Run<T>(Func<object, T> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask<T> Run<T>(Func<object, T> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(func, state, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return func(state);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
await UniTask.Yield();
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return func(state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>[Obsolete]recommend to use RunOnThreadPool(or UniTask.Void(async void), UniTask.Create(async UniTask)).</summary>
|
[Obsolete("UniTask.Run is similar as Task.Run, it uses ThreadPool. For equivalent behaviour, use UniTask.RunOnThreadPool instead. If you don't want to use ThreadPool, you can use UniTask.Void(async void) or UniTask.Create(async UniTask) too.")]
|
||||||
public static async UniTask<T> Run<T>(Func<object, UniTask<T>> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static UniTask<T> Run<T>(Func<object, UniTask<T>> func, object state, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
return RunOnThreadPool(func, state, configureAwait, cancellationToken);
|
||||||
|
|
||||||
await UniTask.SwitchToThreadPool();
|
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
|
|
||||||
if (configureAwait)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return await func(state);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
await UniTask.Yield();
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var result = await func(state);
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
/// <summary>Run action on the threadPool and return to main thread if configureAwait = true.</summary>
|
||||||
public static async UniTask RunOnThreadPool(Action action, bool configureAwait = true, CancellationToken cancellationToken = default)
|
public static async UniTask RunOnThreadPool(Action action, bool configureAwait = true, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -74,16 +74,19 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
static async UniTaskVoid Fire<T>(AsyncSubject<T> subject, UniTask<T> task)
|
static async UniTaskVoid Fire<T>(AsyncSubject<T> subject, UniTask<T> task)
|
||||||
{
|
{
|
||||||
|
T value;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var value = await task;
|
value = await task;
|
||||||
subject.OnNext(value);
|
|
||||||
subject.OnCompleted();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
subject.OnError(ex);
|
subject.OnError(ex);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subject.OnNext(value);
|
||||||
|
subject.OnCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async UniTaskVoid Fire(AsyncSubject<AsyncUnit> subject, UniTask task)
|
static async UniTaskVoid Fire(AsyncSubject<AsyncUnit> subject, UniTask task)
|
||||||
@@ -91,13 +94,15 @@ namespace Cysharp.Threading.Tasks
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await task;
|
await task;
|
||||||
subject.OnNext(AsyncUnit.Default);
|
|
||||||
subject.OnCompleted();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
subject.OnError(ex);
|
subject.OnError(ex);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subject.OnNext(AsyncUnit.Default);
|
||||||
|
subject.OnCompleted();
|
||||||
}
|
}
|
||||||
|
|
||||||
class ToUniTaskObserver<T> : IObserver<T>
|
class ToUniTaskObserver<T> : IObserver<T>
|
||||||
@@ -128,7 +133,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
var self = (ToUniTaskObserver<T>)state;
|
var self = (ToUniTaskObserver<T>)state;
|
||||||
self.disposable.Dispose();
|
self.disposable.Dispose();
|
||||||
self.promise.TrySetCanceled();
|
self.promise.TrySetCanceled(self.cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnNext(T value)
|
public void OnNext(T value)
|
||||||
@@ -198,7 +203,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
var self = (FirstValueToUniTaskObserver<T>)state;
|
var self = (FirstValueToUniTaskObserver<T>)state;
|
||||||
self.disposable.Dispose();
|
self.disposable.Dispose();
|
||||||
self.promise.TrySetCanceled();
|
self.promise.TrySetCanceled(self.cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void OnNext(T value)
|
public void OnNext(T value)
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
|
|
||||||
public static UniTask<UnityEngine.Object[]> AwaitForAllAssets(this AssetBundleRequest asyncOperation, CancellationToken cancellationToken)
|
public static UniTask<UnityEngine.Object[]> AwaitForAllAssets(this AssetBundleRequest asyncOperation, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return AwaitForAllAssets(asyncOperation, cancellationToken: cancellationToken);
|
return AwaitForAllAssets(asyncOperation, null, PlayerLoopTiming.Update, cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UniTask<UnityEngine.Object[]> AwaitForAllAssets(this AssetBundleRequest asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
public static UniTask<UnityEngine.Object[]> AwaitForAllAssets(this AssetBundleRequest asyncOperation, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
|||||||
@@ -15,11 +15,15 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
#region AsyncOperation
|
#region AsyncOperation
|
||||||
|
|
||||||
|
#if !UNITY_2023_1_OR_NEWER
|
||||||
|
// from Unity2023.1.0a15, AsyncOperationAwaitableExtensions.GetAwaiter is defined in UnityEngine.
|
||||||
|
|
||||||
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
public static AsyncOperationAwaiter GetAwaiter(this AsyncOperation asyncOperation)
|
||||||
{
|
{
|
||||||
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
Error.ThrowArgumentNullException(asyncOperation, nameof(asyncOperation));
|
||||||
return new AsyncOperationAwaiter(asyncOperation);
|
return new AsyncOperationAwaiter(asyncOperation);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public static UniTask WithCancellation(this AsyncOperation asyncOperation, CancellationToken cancellationToken)
|
public static UniTask WithCancellation(this AsyncOperation asyncOperation, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -688,13 +688,27 @@ namespace Cysharp.Threading.Tasks
|
|||||||
static void OnCanceled1(object state)
|
static void OnCanceled1(object state)
|
||||||
{
|
{
|
||||||
var self = (UnityEventHandlerAsyncEnumerator)state;
|
var self = (UnityEventHandlerAsyncEnumerator)state;
|
||||||
self.DisposeAsync().Forget();
|
try
|
||||||
|
{
|
||||||
|
self.completionSource.TrySetCanceled(self.cancellationToken1);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
self.DisposeAsync().Forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnCanceled2(object state)
|
static void OnCanceled2(object state)
|
||||||
{
|
{
|
||||||
var self = (UnityEventHandlerAsyncEnumerator)state;
|
var self = (UnityEventHandlerAsyncEnumerator)state;
|
||||||
self.DisposeAsync().Forget();
|
try
|
||||||
|
{
|
||||||
|
self.completionSource.TrySetCanceled(self.cancellationToken2);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
self.DisposeAsync().Forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
@@ -706,6 +720,8 @@ namespace Cysharp.Threading.Tasks
|
|||||||
registration1.Dispose();
|
registration1.Dispose();
|
||||||
registration2.Dispose();
|
registration2.Dispose();
|
||||||
unityEvent.RemoveListener(unityAction);
|
unityEvent.RemoveListener(unityAction);
|
||||||
|
|
||||||
|
completionSource.TrySetCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
@@ -793,13 +809,27 @@ namespace Cysharp.Threading.Tasks
|
|||||||
static void OnCanceled1(object state)
|
static void OnCanceled1(object state)
|
||||||
{
|
{
|
||||||
var self = (UnityEventHandlerAsyncEnumerator)state;
|
var self = (UnityEventHandlerAsyncEnumerator)state;
|
||||||
self.DisposeAsync().Forget();
|
try
|
||||||
|
{
|
||||||
|
self.completionSource.TrySetCanceled(self.cancellationToken1);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
self.DisposeAsync().Forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void OnCanceled2(object state)
|
static void OnCanceled2(object state)
|
||||||
{
|
{
|
||||||
var self = (UnityEventHandlerAsyncEnumerator)state;
|
var self = (UnityEventHandlerAsyncEnumerator)state;
|
||||||
self.DisposeAsync().Forget();
|
try
|
||||||
|
{
|
||||||
|
self.completionSource.TrySetCanceled(self.cancellationToken2);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
self.DisposeAsync().Forget();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public UniTask DisposeAsync()
|
public UniTask DisposeAsync()
|
||||||
@@ -815,6 +845,8 @@ namespace Cysharp.Threading.Tasks
|
|||||||
disp.Dispose();
|
disp.Dispose();
|
||||||
}
|
}
|
||||||
unityEvent.RemoveListener(unityAction);
|
unityEvent.RemoveListener(unityAction);
|
||||||
|
|
||||||
|
completionSource.TrySetCanceled();
|
||||||
}
|
}
|
||||||
|
|
||||||
return default;
|
return default;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
#if ENABLE_UNITYWEBREQUEST && (!UNITY_2019_1_OR_NEWER || UNITASK_WEBREQUEST_SUPPORT)
|
#if ENABLE_UNITYWEBREQUEST && (!UNITY_2019_1_OR_NEWER || UNITASK_WEBREQUEST_SUPPORT)
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks
|
|||||||
{
|
{
|
||||||
if (msg == null)
|
if (msg == null)
|
||||||
{
|
{
|
||||||
if (Text != null)
|
if(!string.IsNullOrWhiteSpace(Text))
|
||||||
{
|
{
|
||||||
msg = Error + Environment.NewLine + Text;
|
msg = Error + Environment.NewLine + Text;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "com.cysharp.unitask",
|
"name": "com.cysharp.unitask",
|
||||||
"displayName": "UniTask",
|
"displayName": "UniTask",
|
||||||
"version": "2.2.3",
|
"author": { "name": "Cysharp, Inc.", "url": "https://cysharp.co.jp/en/" },
|
||||||
|
"version": "2.3.2",
|
||||||
"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" ],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"category": "Task",
|
"category": "Task",
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -543,7 +543,7 @@ public class SandboxMain : MonoBehaviour
|
|||||||
Debug.LogError(e);
|
Debug.LogError(e);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Debug.Log("TestAsync Finished.");
|
Debug.Log("TestAsync Finished.");
|
||||||
@@ -555,6 +555,7 @@ public class SandboxMain : MonoBehaviour
|
|||||||
async UniTaskVoid Start()
|
async UniTaskVoid Start()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
// UniTask.Delay(TimeSpan.FromSeconds(1)).TimeoutWithoutException
|
// UniTask.Delay(TimeSpan.FromSeconds(1)).TimeoutWithoutException
|
||||||
|
|
||||||
|
|
||||||
@@ -562,61 +563,34 @@ public class SandboxMain : MonoBehaviour
|
|||||||
PlayerLoopHelper.Initialize(ref currentLoop, InjectPlayerLoopTimings.Minimum); // minimum is Update | FixedUpdate | LastPostLateUpdate
|
PlayerLoopHelper.Initialize(ref currentLoop, InjectPlayerLoopTimings.Minimum); // minimum is Update | FixedUpdate | LastPostLateUpdate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var cancelToken = new CancellationTokenSource();
|
|
||||||
cancelButton.onClick.AddListener(()=>
|
|
||||||
{
|
|
||||||
cancelToken.Cancel(); // cancel from button click.
|
|
||||||
});
|
|
||||||
|
|
||||||
var timeoutToken = new CancellationTokenSource();
|
|
||||||
timeoutToken.CancelAfterSlim(TimeSpan.FromSeconds(5)); // 5sec timeout.
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// combine token
|
|
||||||
var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancelToken.Token, timeoutToken.Token);
|
|
||||||
|
|
||||||
await UnityWebRequest.Get("http://foo").SendWebRequest().WithCancellation(linkedTokenSource.Token);
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException ex)
|
|
||||||
{
|
|
||||||
if (timeoutToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.Log("Timeout.");
|
|
||||||
}
|
|
||||||
else if (cancelToken.IsCancellationRequested)
|
|
||||||
{
|
|
||||||
UnityEngine.Debug.Log("Cancel clicked.");
|
|
||||||
}
|
|
||||||
_ = ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TestAsync(cts.Token).Forget();
|
// TestAsync(cts.Token).Forget();
|
||||||
|
|
||||||
okButton.onClick.AddListener(UniTask.UnityAction(async () =>
|
okButton.onClick.AddListener(UniTask.UnityAction(async () =>
|
||||||
{
|
{
|
||||||
// try timeout
|
await UniTask.WaitForEndOfFrame(this);
|
||||||
try
|
var texture = new Texture2D(Screen.width, Screen.height);
|
||||||
{
|
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
|
||||||
//await UniTask.Delay(TimeSpan.FromSeconds(2), cancellationToken: timeoutController.Timeout(TimeSpan.FromSeconds(3)));
|
texture.Apply();
|
||||||
UnityEngine.Debug.Log("Delay Complete, Reset(and reuse).");
|
|
||||||
//timeoutController.Reset();
|
|
||||||
}
|
|
||||||
catch (OperationCanceledException ex)
|
|
||||||
{
|
|
||||||
//UnityEngine.Debug.Log("Timeout! FromTimeout?:" + timeoutController.IsTimeout());
|
|
||||||
_ = ex;
|
|
||||||
}
|
|
||||||
|
|
||||||
await UniTask.Yield();
|
var jpg = texture.EncodeToJPG();
|
||||||
|
File.WriteAllBytes("testscreencapture.jpg", jpg);
|
||||||
|
Debug.Log("ok?");
|
||||||
|
|
||||||
|
//var texture = ScreenCapture.CaptureScreenshotAsTexture();
|
||||||
|
//if (texture == null)
|
||||||
|
//{
|
||||||
|
// Debug.Log("fail");
|
||||||
|
//}
|
||||||
|
//else
|
||||||
|
//{
|
||||||
|
// var jpg = texture.EncodeToJPG();
|
||||||
|
// File.WriteAllBytes("testscreencapture.jpg", jpg);
|
||||||
|
// Debug.Log("ok?");
|
||||||
|
//}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
cancelButton.onClick.AddListener(UniTask.UnityAction(async () =>
|
cancelButton.onClick.AddListener(UniTask.UnityAction(async () =>
|
||||||
|
|||||||
@@ -310,33 +310,33 @@ namespace Cysharp.Threading.TasksTests
|
|||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[UnityTest]
|
//[UnityTest]
|
||||||
public IEnumerator ExceptionUnobserved1() => UniTask.ToCoroutine(async () =>
|
//public IEnumerator ExceptionUnobserved1() => UniTask.ToCoroutine(async () =>
|
||||||
{
|
//{
|
||||||
bool calledEx = false;
|
// bool calledEx = false;
|
||||||
Action<Exception> action = exx =>
|
// Action<Exception> action = exx =>
|
||||||
{
|
// {
|
||||||
calledEx = true;
|
// calledEx = true;
|
||||||
exx.Message.Should().Be("MyException");
|
// exx.Message.Should().Be("MyException");
|
||||||
};
|
// };
|
||||||
|
|
||||||
UniTaskScheduler.UnobservedTaskException += action;
|
// UniTaskScheduler.UnobservedTaskException += action;
|
||||||
|
|
||||||
var ex = InException1();
|
// var ex = InException1();
|
||||||
ex = default(UniTask);
|
// ex = default(UniTask);
|
||||||
|
|
||||||
await UniTask.DelayFrame(3);
|
// await UniTask.DelayFrame(3);
|
||||||
|
|
||||||
GC.Collect();
|
// GC.Collect();
|
||||||
GC.WaitForPendingFinalizers();
|
// GC.WaitForPendingFinalizers();
|
||||||
GC.Collect();
|
// GC.Collect();
|
||||||
|
|
||||||
await UniTask.DelayFrame(1);
|
// await UniTask.DelayFrame(1);
|
||||||
|
|
||||||
calledEx.Should().BeTrue();
|
// calledEx.Should().BeTrue();
|
||||||
|
|
||||||
UniTaskScheduler.UnobservedTaskException -= action;
|
// UniTaskScheduler.UnobservedTaskException -= action;
|
||||||
});
|
//});
|
||||||
|
|
||||||
[UnityTest]
|
[UnityTest]
|
||||||
public IEnumerator ExceptionUnobserved2() => UniTask.ToCoroutine(async () =>
|
public IEnumerator ExceptionUnobserved2() => UniTask.ToCoroutine(async () =>
|
||||||
@@ -366,6 +366,29 @@ namespace Cysharp.Threading.TasksTests
|
|||||||
UniTaskScheduler.UnobservedTaskException -= action;
|
UniTaskScheduler.UnobservedTaskException -= action;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// can not run on RuntimeUnitTestToolkit so ignore...
|
||||||
|
// [UnityTest]
|
||||||
|
// public IEnumerator ThrowExceptionUnawaited() => UniTask.ToCoroutine(async () =>
|
||||||
|
// {
|
||||||
|
// LogAssert.Expect(LogType.Exception, "Exception: MyException");
|
||||||
|
|
||||||
|
//#pragma warning disable 1998
|
||||||
|
// async UniTask Throw() => throw new Exception("MyException");
|
||||||
|
//#pragma warning restore 1998
|
||||||
|
|
||||||
|
//#pragma warning disable 4014
|
||||||
|
// Throw();
|
||||||
|
//#pragma warning restore 4014
|
||||||
|
|
||||||
|
// await UniTask.DelayFrame(3);
|
||||||
|
|
||||||
|
// GC.Collect();
|
||||||
|
// GC.WaitForPendingFinalizers();
|
||||||
|
// GC.Collect();
|
||||||
|
|
||||||
|
// await UniTask.DelayFrame(1);
|
||||||
|
// });
|
||||||
|
|
||||||
async UniTask InException1()
|
async UniTask InException1()
|
||||||
{
|
{
|
||||||
await UniTask.Yield();
|
await UniTask.Yield();
|
||||||
|
|||||||
179
src/UniTask/Assets/Tests/PlayerLoopTimerTest.cs
Normal file
179
src/UniTask/Assets/Tests/PlayerLoopTimerTest.cs
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
using Cysharp.Threading.Tasks;
|
||||||
|
using FluentAssertions;
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using UnityEngine.TestTools;
|
||||||
|
|
||||||
|
namespace Cysharp.Threading.TasksTests
|
||||||
|
{
|
||||||
|
public class PlayerLoopTimerTest
|
||||||
|
{
|
||||||
|
void Between(TimeSpan l, TimeSpan data, TimeSpan r)
|
||||||
|
{
|
||||||
|
NUnit.Framework.Assert.AreEqual(l < data, true, "{0} < {1} failed.", l, data);
|
||||||
|
NUnit.Framework.Assert.AreEqual(data < r, true, "{0} < {1} failed.", data, r);
|
||||||
|
}
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator StandardTicks() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
foreach (var delay in new[] { DelayType.DeltaTime, DelayType.Realtime, DelayType.UnscaledDeltaTime })
|
||||||
|
{
|
||||||
|
var raisedTimeout = new UniTaskCompletionSource();
|
||||||
|
PlayerLoopTimer.StartNew(TimeSpan.FromSeconds(1), false, delay, PlayerLoopTiming.Update, CancellationToken.None, _ =>
|
||||||
|
{
|
||||||
|
raisedTimeout.TrySetResult();
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
await raisedTimeout.Task;
|
||||||
|
sw.Stop();
|
||||||
|
|
||||||
|
Between(TimeSpan.FromSeconds(0.9), sw.Elapsed, TimeSpan.FromSeconds(1.1));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator Periodic() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var raisedTime = new List<DateTime>();
|
||||||
|
var count = 0;
|
||||||
|
var complete = new UniTaskCompletionSource();
|
||||||
|
|
||||||
|
PlayerLoopTimer timer = null;
|
||||||
|
timer = PlayerLoopTimer.StartNew(TimeSpan.FromSeconds(1), true, DelayType.DeltaTime, PlayerLoopTiming.Update, CancellationToken.None, _ =>
|
||||||
|
{
|
||||||
|
raisedTime.Add(DateTime.UtcNow);
|
||||||
|
count++;
|
||||||
|
if (count == 3)
|
||||||
|
{
|
||||||
|
complete.TrySetResult();
|
||||||
|
timer.Dispose();
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
var start = DateTime.UtcNow;
|
||||||
|
await complete.Task;
|
||||||
|
|
||||||
|
Between(TimeSpan.FromSeconds(0.9), raisedTime[0] - start, TimeSpan.FromSeconds(1.1));
|
||||||
|
Between(TimeSpan.FromSeconds(1.9), raisedTime[1] - start, TimeSpan.FromSeconds(2.1));
|
||||||
|
Between(TimeSpan.FromSeconds(2.9), raisedTime[2] - start, TimeSpan.FromSeconds(3.1));
|
||||||
|
});
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator CancelAfterSlimTest() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
|
var complete = new UniTaskCompletionSource();
|
||||||
|
cts.Token.RegisterWithoutCaptureExecutionContext(() =>
|
||||||
|
{
|
||||||
|
complete.TrySetResult();
|
||||||
|
});
|
||||||
|
|
||||||
|
cts.CancelAfterSlim(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
await complete.Task;
|
||||||
|
|
||||||
|
Between(TimeSpan.FromSeconds(0.9), sw.Elapsed, TimeSpan.FromSeconds(1.1));
|
||||||
|
});
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator CancelAfterSlimCancelTest() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
|
var complete = new UniTaskCompletionSource();
|
||||||
|
cts.Token.RegisterWithoutCaptureExecutionContext(() =>
|
||||||
|
{
|
||||||
|
complete.TrySetResult();
|
||||||
|
});
|
||||||
|
|
||||||
|
var d = cts.CancelAfterSlim(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
await UniTask.Delay(TimeSpan.FromMilliseconds(100));
|
||||||
|
d.Dispose();
|
||||||
|
|
||||||
|
await UniTask.Delay(TimeSpan.FromSeconds(2));
|
||||||
|
|
||||||
|
complete.Task.Status.Should().Be(UniTaskStatus.Pending);
|
||||||
|
});
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TimeoutController() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var controller = new TimeoutController();
|
||||||
|
|
||||||
|
var token = controller.Timeout(TimeSpan.FromSeconds(1));
|
||||||
|
|
||||||
|
var complete = new UniTaskCompletionSource();
|
||||||
|
token.RegisterWithoutCaptureExecutionContext(() =>
|
||||||
|
{
|
||||||
|
complete.TrySetResult();
|
||||||
|
});
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
await complete.Task;
|
||||||
|
Between(TimeSpan.FromSeconds(0.9), sw.Elapsed, TimeSpan.FromSeconds(1.1));
|
||||||
|
|
||||||
|
controller.IsTimeout().Should().BeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator TimeoutReuse() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var controller = new TimeoutController(DelayType.DeltaTime);
|
||||||
|
|
||||||
|
var token = controller.Timeout(TimeSpan.FromSeconds(2));
|
||||||
|
|
||||||
|
var complete = new UniTaskCompletionSource();
|
||||||
|
token.RegisterWithoutCaptureExecutionContext(() =>
|
||||||
|
{
|
||||||
|
complete.TrySetResult(); // reuse, used same token?
|
||||||
|
});
|
||||||
|
|
||||||
|
await UniTask.Delay(TimeSpan.FromMilliseconds(100));
|
||||||
|
controller.Reset();
|
||||||
|
|
||||||
|
controller.IsTimeout().Should().BeFalse();
|
||||||
|
|
||||||
|
var sw = Stopwatch.StartNew();
|
||||||
|
|
||||||
|
controller.Timeout(TimeSpan.FromSeconds(5));
|
||||||
|
|
||||||
|
await complete.Task;
|
||||||
|
|
||||||
|
UnityEngine.Debug.Log(UnityEngine.Time.timeScale);
|
||||||
|
Between(TimeSpan.FromSeconds(4.9), sw.Elapsed, TimeSpan.FromSeconds(5.1));
|
||||||
|
|
||||||
|
controller.IsTimeout().Should().BeTrue();
|
||||||
|
});
|
||||||
|
|
||||||
|
[UnityTest]
|
||||||
|
public IEnumerator LinkedTokenTest() => UniTask.ToCoroutine(async () =>
|
||||||
|
{
|
||||||
|
var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
var controller = new TimeoutController(cts);
|
||||||
|
var token = controller.Timeout(TimeSpan.FromSeconds(2));
|
||||||
|
|
||||||
|
await UniTask.DelayFrame(3);
|
||||||
|
|
||||||
|
cts.Cancel();
|
||||||
|
|
||||||
|
token.IsCancellationRequested.Should().BeTrue();
|
||||||
|
|
||||||
|
controller.Dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/UniTask/Assets/Tests/PlayerLoopTimerTest.cs.meta
Normal file
11
src/UniTask/Assets/Tests/PlayerLoopTimerTest.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: c0c49de697f829f44aa8709b4d1eff3e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Reference in New Issue
Block a user