mirror of
https://github.com/Cysharp/UniTask.git
synced 2026-05-15 03:20:16 +00:00
Compare commits
53 Commits
2.0.3-prev
...
2.0.10-rc7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eca5b1c096 | ||
|
|
c74ce14ad1 | ||
|
|
f59c56506f | ||
|
|
896eef1ee4 | ||
|
|
ec0123eec7 | ||
|
|
78f56b9b33 | ||
|
|
1d88ed85bc | ||
|
|
2b7986da19 | ||
|
|
c3d22968e1 | ||
|
|
0e25122ee2 | ||
|
|
4504d84aa8 | ||
|
|
2b87cadba3 | ||
|
|
21dc83c641 | ||
|
|
3b593f349c | ||
|
|
962c215e3b | ||
|
|
42dcfdbcdc | ||
|
|
6d7e6ec871 | ||
|
|
36d53a3bcb | ||
|
|
ea9e61c2e1 | ||
|
|
a52c26102b | ||
|
|
e31c87b8a8 | ||
|
|
cc165a6897 | ||
|
|
f99910d802 | ||
|
|
997b0b3710 | ||
|
|
ec7064083a | ||
|
|
07cccfddd6 | ||
|
|
f07527cd06 | ||
|
|
7b273c4bd1 | ||
|
|
d36e7987b3 | ||
|
|
bbd5686816 | ||
|
|
fb1152d8f4 | ||
|
|
7a306118f5 | ||
|
|
efaf3ee8f5 | ||
|
|
2e4fe90956 | ||
|
|
e33d572104 | ||
|
|
2b2af9e455 | ||
|
|
d003597662 | ||
|
|
ec0a8f5a8b | ||
|
|
49ba57f20a | ||
|
|
6f4d1183cc | ||
|
|
dd18c9fff8 | ||
|
|
21f5f78ff1 | ||
|
|
1729f389db | ||
|
|
6d37bb7bac | ||
|
|
957adfad7a | ||
|
|
3ef889e17d | ||
|
|
c73af7390f | ||
|
|
c5b4376486 | ||
|
|
ba65049dd8 | ||
|
|
ee58aab0a9 | ||
|
|
859eaa2278 | ||
|
|
79f770e687 | ||
|
|
8ff4de67a1 |
@@ -1,114 +0,0 @@
|
||||
version: 2.1
|
||||
executors:
|
||||
unity:
|
||||
# https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
parameters:
|
||||
version: {type: string}
|
||||
docker:
|
||||
- image: gableroux/unity3d:<< parameters.version >>
|
||||
go:
|
||||
docker:
|
||||
- image: circleci/golang
|
||||
commands:
|
||||
unity_activate:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
steps:
|
||||
# get activation file, if fail to activate unity, use this key and activate from https://license.unity3d.com/manual
|
||||
- run: apt update && apt install libunwind8 -y
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -logFile -createManualActivationFile || exit 0
|
||||
- run: cat Unity_v<< parameters.unity_version >>.alf
|
||||
# get from UNITY_LICENSE envvar(base64 encoded(cat foo.ulf | base64 )), this file is generated from above manual activation
|
||||
- run: echo << parameters.unity_license >> | base64 -di >> .circleci/Unity.ulf
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .circleci/Unity.ulf || exit 0
|
||||
jobs:
|
||||
build-and-test:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
executor:
|
||||
name: unity
|
||||
version: << parameters.unity_version >>
|
||||
steps:
|
||||
- checkout
|
||||
- unity_activate:
|
||||
unity_version: << parameters.unity_version >>
|
||||
unity_license: << parameters.unity_license >>
|
||||
- run:
|
||||
name: Build Linux(Mono)
|
||||
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend Mono2x /BuildTarget StandaloneLinux64
|
||||
working_directory: .
|
||||
# TODO:check unity version and packages...
|
||||
# - run: ./bin/UnitTest/StandaloneLinux64_Mono2x/test
|
||||
build-and-create-package:
|
||||
parameters:
|
||||
unity_version: {type: string}
|
||||
unity_license: {type: string}
|
||||
executor:
|
||||
name: unity
|
||||
version: << parameters.unity_version >>
|
||||
steps:
|
||||
- checkout
|
||||
- unity_activate:
|
||||
unity_version: << parameters.unity_version >>
|
||||
unity_license: << parameters.unity_license >>
|
||||
- run:
|
||||
name: Export unitypackage
|
||||
command: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
working_directory: .
|
||||
- store_artifacts:
|
||||
path: ./UniRx.Async.unitypackage
|
||||
destination: /UniRx.Async.unitypackage
|
||||
# upload to github by ghr
|
||||
upload-github:
|
||||
executor: go
|
||||
steps:
|
||||
- attach_workspace:
|
||||
at: .
|
||||
- run: go get github.com/tcnksm/ghr
|
||||
- run: ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} ${CIRCLE_TAG} .
|
||||
- store_artifacts:
|
||||
path: UniRx.Async.unitypackage
|
||||
destination: UniRx.Async.unitypackage
|
||||
workflows:
|
||||
version: 2
|
||||
build-unity:
|
||||
jobs:
|
||||
# does not exists yet.
|
||||
# - build-and-test:
|
||||
# unity_version: 2019.3.0a2
|
||||
# unity_license: ${UNITY_LICENSE_2019_3}
|
||||
# - build-and-test:
|
||||
# unity_version: 2019.2.0b2
|
||||
# unity_license: ${UNITY_LICENSE_2019_2}
|
||||
- build-and-test:
|
||||
unity_version: 2019.1.2f1
|
||||
unity_license: ${UNITY_LICENSE_2019_1}
|
||||
filters:
|
||||
tags:
|
||||
only: /.*/
|
||||
# test asmdef will not found.
|
||||
# - build-and-test:
|
||||
# unity_version: 2018.4.0f1
|
||||
# unity_license: ${UNITY_LICENSE_2018_4}
|
||||
# # UniTask minimum support version is 2018.3(C# 7.x)
|
||||
# - build-and-test:
|
||||
# unity_version: 2018.3.12f1
|
||||
# unity_license: ${UNITY_LICENSE_2018_3}
|
||||
- build-and-create-package:
|
||||
unity_version: 2019.1.2f1
|
||||
unity_license: ${UNITY_LICENSE_2019_1}
|
||||
filters:
|
||||
tags:
|
||||
only: /^\d\.\d\.\d.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
- upload-github:
|
||||
requires:
|
||||
- build-and-create-package
|
||||
filters:
|
||||
tags:
|
||||
only: /^\d\.\d\.\d.*/
|
||||
branches:
|
||||
ignore: /.*/
|
||||
73
.github/workflows/build-debug.yml
vendored
Normal file
73
.github/workflows/build-debug.yml
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
name: Build-Debug
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- "**"
|
||||
tags:
|
||||
- "!*" # not a tag push
|
||||
pull_request:
|
||||
types:
|
||||
- opened
|
||||
- synchronize
|
||||
|
||||
jobs:
|
||||
build-dotnet:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
- run: dotnet test -c Debug ./src/UniTask.NetCoreTests/UniTask.NetCoreTests.csproj
|
||||
|
||||
build-unity:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ['2019.3.9f1', '2020.1.0b5']
|
||||
include:
|
||||
- unity: 2019.3.9f1
|
||||
license: UNITY_2019_3
|
||||
- unity: 2020.1.0b5
|
||||
license: UNITY_2020_1
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# with linux-il2cpp. image from https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
image: gableroux/unity3d:${{ matrix.unity }}-linux-il2cpp
|
||||
steps:
|
||||
- run: apt update && apt install git -y
|
||||
- uses: actions/checkout@v2
|
||||
# create unity activation file and store to artifacts.
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -logFile -createManualActivationFile || exit 0
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Unity_v${{ matrix.unity }}.alf
|
||||
path: ./Unity_v${{ matrix.unity }}.alf
|
||||
# activate Unity from manual license file(ulf)
|
||||
- run: echo -n "$UNITY_LICENSE" >> .Unity.ulf
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||
- name: Activate Unity, always returns a success. But if a subsequent run fails, the activation may have failed(if succeeded, shows `Next license update check is after` and not shows other message(like GUID != GUID). If fails not). In that case, upload the artifact's .alf file to https://license.unity3d.com/manual to get the .ulf file and set it to secrets.
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0
|
||||
|
||||
# Execute scripts: RuntimeUnitTestToolkit
|
||||
- name: Build UnitTest(Linux64, mono)
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
|
||||
working-directory: src/UniTask
|
||||
- name: Execute UnitTest
|
||||
run: ./src/UniTask/bin/UnitTest/StandaloneLinux64_Mono2x/test
|
||||
|
||||
# Execute scripts: Export Package
|
||||
- name: Export unitypackage
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
working-directory: src/UniTask
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: UniTask.unitypackage.zip
|
||||
path: ./src/UniTask/*.unitypackage
|
||||
108
.github/workflows/build-release.yml
vendored
Normal file
108
.github/workflows/build-release.yml
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
name: Build-Release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "[0-9]+.[0-9]+.[0-9]+*"
|
||||
|
||||
jobs:
|
||||
build-dotnet:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
|
||||
# build CommandTools first (use dotnet run command in ZLogger.csproj)
|
||||
- run: dotnet build -c Release ./tools/CommandTools/CommandTools.csproj
|
||||
- run: dotnet build -c Release -p:Version=${{ env.GIT_TAG }}
|
||||
- run: dotnet test -c Release --no-build
|
||||
- run: dotnet pack ./src/ZLogger/ZLogger.csproj -c Release --no-build -p:Version=${{ env.GIT_TAG }}
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: nuget
|
||||
path: ./src/ZLogger/bin/Release/ZLogger.${{ env.GIT_TAG }}.nupkg
|
||||
|
||||
build-unity:
|
||||
strategy:
|
||||
matrix:
|
||||
unity: ['2019.3.9f1']
|
||||
include:
|
||||
- unity: 2019.3.9f1
|
||||
license: UNITY_2019_3
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
# with linux-il2cpp. image from https://hub.docker.com/r/gableroux/unity3d/tags
|
||||
image: gableroux/unity3d:${{ matrix.unity }}-linux-il2cpp
|
||||
steps:
|
||||
- run: apt update && apt install git -y
|
||||
- uses: actions/checkout@v2
|
||||
- run: echo -n "$UNITY_LICENSE" >> .Unity.ulf
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets[matrix.license] }}
|
||||
- run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -manualLicenseFile .Unity.ulf || exit 0
|
||||
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
|
||||
# Execute scripts: Export Package
|
||||
- name: Export unitypackage
|
||||
run: /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
|
||||
working-directory: src/ZLogger.Unity
|
||||
env:
|
||||
UNITY_PACKAGE_VERSION: ${{ env.GIT_TAG }}
|
||||
|
||||
# Store artifacts.
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
path: ./src/ZLogger.Unity/ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
|
||||
create-release:
|
||||
needs: [build-dotnet, build-unity]
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
DOTNET_CLI_TELEMETRY_OPTOUT: 1
|
||||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
|
||||
NUGET_XMLDOC_MODE: skip
|
||||
steps:
|
||||
# setup dotnet for nuget push
|
||||
- uses: actions/setup-dotnet@v1
|
||||
with:
|
||||
dotnet-version: 3.1.101
|
||||
# set release tag(*.*.*) to env.GIT_TAG
|
||||
- run: echo ::set-env name=GIT_TAG::${GITHUB_REF#refs/tags/}
|
||||
|
||||
# Create Releases
|
||||
- uses: actions/create-release@v1
|
||||
id: create_release
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
tag_name: ${{ github.ref }}
|
||||
release_name: Ver.${{ github.ref }}
|
||||
|
||||
# Download (All) Artifacts to current directory
|
||||
- uses: actions/download-artifact@v2-preview
|
||||
|
||||
# Upload to NuGet
|
||||
- run: dotnet nuget push "./nuget/*.nupkg" -s https://www.nuget.org/api/v2/package -k ${{ secrets.NUGET_KEY }}
|
||||
|
||||
# Upload to Releases(unitypackage)
|
||||
- uses: actions/upload-release-asset@v1
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
with:
|
||||
upload_url: ${{ steps.create_release.outputs.upload_url }}
|
||||
asset_path: ./ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage/ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_name: ZLogger.Unity.${{ env.GIT_TAG }}.unitypackage
|
||||
asset_content_type: application/octet-stream
|
||||
15
.github/workflows/toc.yml
vendored
Normal file
15
.github/workflows/toc.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
name: TOC Generator
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- 'README.md'
|
||||
|
||||
jobs:
|
||||
generateTOC:
|
||||
name: TOC Generator
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: technote-space/toc-generator@v2.4.0
|
||||
with:
|
||||
TOC_TITLE: "## Table of Contents"
|
||||
36
README.md
36
README.md
@@ -1,10 +1,29 @@
|
||||
# UniTask
|
||||
|
||||
[](https://circleci.com/gh/Cysharp/UniTask)
|
||||
UniTask
|
||||
===
|
||||
[](https://github.com/Cysharp/UniTask/actions) [](https://github.com/Cysharp/UniTask/releases)
|
||||
|
||||
Provides an efficient async/await integration to Unity.
|
||||
|
||||
> UniTask was included in UniRx before v7 but now completely separated, it no dependent each other.
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
## Table of Contents
|
||||
|
||||
- [Getting started](#getting-started)
|
||||
- [`UniTask<T>`](#unitaskt)
|
||||
- [Cancellation and Exception handling](#cancellation-and-exception-handling)
|
||||
- [Progress](#progress)
|
||||
- [UniTaskTracker](#unitasktracker)
|
||||
- [Reusable Promises](#reusable-promises)
|
||||
- [awaitable Events](#awaitable-events)
|
||||
- [async void vs async UniTask/UniTaskVoid](#async-void-vs-async-unitaskunitaskvoid)
|
||||
- [For Unit Testing](#for-unit-testing)
|
||||
- [Method List](#method-list)
|
||||
- [UPM Package](#upm-package)
|
||||
- [ECS, PlayerLoop](#ecs-playerloop)
|
||||
- [License](#license)
|
||||
|
||||
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
||||
|
||||
|
||||
Getting started
|
||||
---
|
||||
@@ -354,6 +373,15 @@ or add `"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=Asse
|
||||
|
||||
If you want to set a target version, UniTask is using `*.*.*` release tag so you can specify a version like `#1.3.0`. For example `https://github.com/Cysharp/UniTask.git?path=Assets/UniRx.Async#1.3.1`.
|
||||
|
||||
ECS, PlayerLoop
|
||||
---
|
||||
TODO:
|
||||
|
||||
```csharp
|
||||
var loop = PlayerLoop.GetCurrentPlayerLoop();
|
||||
PlayerLoopHelper.Initialize(ref loop);
|
||||
```
|
||||
|
||||
License
|
||||
---
|
||||
This library is under the MIT License.
|
||||
@@ -16,6 +16,7 @@
|
||||
..\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\CancellationTokenSourceExtensions.cs;
|
||||
..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs;
|
||||
@@ -27,6 +28,7 @@
|
||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.cs;
|
||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.uGUI.cs;
|
||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.MonoBehaviour.cs;
|
||||
..\UniTask\Assets\Plugins\UniTask\Runtime\UnityBindingExtensions.cs;
|
||||
" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -15,6 +15,55 @@ using System.Reactive.Concurrency;
|
||||
|
||||
namespace NetCoreSandbox
|
||||
{
|
||||
public class Text
|
||||
{
|
||||
|
||||
public string text { get; set; }
|
||||
}
|
||||
|
||||
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)
|
||||
@@ -37,29 +86,23 @@ namespace NetCoreSandbox
|
||||
await Task.Delay(10, cancellationToken);
|
||||
}
|
||||
|
||||
static async Task Main(string[] args)
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
await foreach (var item in UniTaskAsyncEnumerable.Range(1, 10)
|
||||
.SelectAwait(x => UniTask.Run(() => x))
|
||||
.TakeLast(6)
|
||||
|
||||
|
||||
var channel = Channel.CreateSingleConsumerUnbounded<int>();
|
||||
|
||||
)
|
||||
{
|
||||
// Observable.Range(1,10).CombineLatest(
|
||||
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
// AsyncEnumerable.Range(1,10).FirstAsync(
|
||||
// AsyncEnumerable.Range(1, 10).GroupBy(x=>x).Select(x=>x.first
|
||||
var token = cts.Token;
|
||||
|
||||
FooAsync(token).ForEachAsync(x => { }, token);
|
||||
|
||||
|
||||
// AsyncEnumerable.Range(1,10).WithCancellation(CancellationToken.None).WithCancellation
|
||||
|
||||
|
||||
//Enumerable.Range(1,10).ToHashSet(
|
||||
|
||||
// Observable.Range(1,10).CombineLatest(
|
||||
|
||||
}
|
||||
|
||||
|
||||
118
src/UniTask.NetCoreTests/AsyncReactivePropertyTest.cs
Normal file
118
src/UniTask.NetCoreTests/AsyncReactivePropertyTest.cs
Normal file
@@ -0,0 +1,118 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests
|
||||
{
|
||||
public class AsyncReactivePropertyTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task Iteration()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(99);
|
||||
|
||||
var f = await rp.FirstAsync();
|
||||
f.Should().Be(99);
|
||||
|
||||
var array = rp.Take(5).ToArrayAsync();
|
||||
|
||||
rp.Value = 100;
|
||||
rp.Value = 100;
|
||||
rp.Value = 100;
|
||||
rp.Value = 131;
|
||||
|
||||
var ar = await array;
|
||||
|
||||
ar.Should().BeEquivalentTo(new[] { 99, 100, 100, 100, 131 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task WithoutCurrent()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(99);
|
||||
|
||||
var array = rp.WithoutCurrent().Take(5).ToArrayAsync();
|
||||
|
||||
rp.Value = 100;
|
||||
rp.Value = 100;
|
||||
rp.Value = 100;
|
||||
rp.Value = 131;
|
||||
rp.Value = 191;
|
||||
|
||||
var ar = await array;
|
||||
|
||||
ar.Should().BeEquivalentTo(new[] { 100, 100, 100, 131, 191 });
|
||||
}
|
||||
|
||||
//[Fact]
|
||||
//public async Task StateIteration()
|
||||
//{
|
||||
// var rp = new ReadOnlyAsyncReactiveProperty<int>(99);
|
||||
// var setter = rp.GetSetter();
|
||||
|
||||
// var f = await rp.FirstAsync();
|
||||
// f.Should().Be(99);
|
||||
|
||||
// var array = rp.Take(5).ToArrayAsync();
|
||||
|
||||
// setter(100);
|
||||
// setter(100);
|
||||
// setter(100);
|
||||
// setter(131);
|
||||
|
||||
// var ar = await array;
|
||||
|
||||
// ar.Should().BeEquivalentTo(new[] { 99, 100, 100, 100, 131 });
|
||||
//}
|
||||
|
||||
//[Fact]
|
||||
//public async Task StateWithoutCurrent()
|
||||
//{
|
||||
// var rp = new ReadOnlyAsyncReactiveProperty<int>(99);
|
||||
// var setter = rp.GetSetter();
|
||||
|
||||
// var array = rp.WithoutCurrent().Take(5).ToArrayAsync();
|
||||
// setter(100);
|
||||
// setter(100);
|
||||
// setter(100);
|
||||
// setter(131);
|
||||
// setter(191);
|
||||
|
||||
// var ar = await array;
|
||||
|
||||
// ar.Should().BeEquivalentTo(new[] { 100, 100, 100, 131, 191 });
|
||||
//}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public void StateFromEnumeration()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(10);
|
||||
|
||||
var state = rp.ToReadOnlyAsyncReactiveProperty(CancellationToken.None);
|
||||
|
||||
rp.Value = 10;
|
||||
state.Value.Should().Be(10);
|
||||
|
||||
rp.Value = 20;
|
||||
state.Value.Should().Be(20);
|
||||
|
||||
state.Dispose();
|
||||
|
||||
rp.Value = 30;
|
||||
state.Value.Should().Be(20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
51
src/UniTask.NetCoreTests/CancellationTokenTest.cs
Normal file
51
src/UniTask.NetCoreTests/CancellationTokenTest.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests
|
||||
{
|
||||
public class CancellationTokenTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task WaitUntilCanceled()
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
cts.CancelAfter(TimeSpan.FromSeconds(1.5));
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
await cts.Token.WaitUntilCanceled();
|
||||
|
||||
var elapsed = DateTime.UtcNow - now;
|
||||
|
||||
elapsed.Should().BeGreaterThan(TimeSpan.FromSeconds(1));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AlreadyCanceled()
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
cts.Cancel();
|
||||
|
||||
cts.Token.WaitUntilCanceled().GetAwaiter().IsCompleted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void None()
|
||||
{
|
||||
CancellationToken.None.WaitUntilCanceled().GetAwaiter().IsCompleted.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
370
src/UniTask.NetCoreTests/ChannelTest.cs
Normal file
370
src/UniTask.NetCoreTests/ChannelTest.cs
Normal file
@@ -0,0 +1,370 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests
|
||||
{
|
||||
public class ChannelTest
|
||||
{
|
||||
(System.Threading.Channels.Channel<int>, Cysharp.Threading.Tasks.Channel<int>) CreateChannel()
|
||||
{
|
||||
var reference = System.Threading.Channels.Channel.CreateUnbounded<int>(new UnboundedChannelOptions
|
||||
{
|
||||
AllowSynchronousContinuations = true,
|
||||
SingleReader = true,
|
||||
SingleWriter = false
|
||||
});
|
||||
|
||||
var channel = Cysharp.Threading.Tasks.Channel.CreateSingleConsumerUnbounded<int>();
|
||||
|
||||
return (reference, channel);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SingleWriteSingleRead()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
var t1 = reference.Reader.WaitToReadAsync();
|
||||
var t2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
t1.IsCompleted.Should().BeFalse();
|
||||
t2.Status.IsCompleted().Should().BeFalse();
|
||||
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
|
||||
(await t1).Should().BeTrue();
|
||||
(await t2).Should().BeTrue();
|
||||
|
||||
reference.Reader.TryRead(out var refitem).Should().BeTrue();
|
||||
channel.Reader.TryRead(out var chanitem).Should().BeTrue();
|
||||
refitem.Should().Be(item);
|
||||
chanitem.Should().Be(item);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task MultiWrite()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
var t1 = reference.Reader.WaitToReadAsync();
|
||||
var t2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
t1.IsCompleted.Should().BeFalse();
|
||||
t2.Status.IsCompleted().Should().BeFalse();
|
||||
|
||||
foreach (var i in Enumerable.Range(1, 3))
|
||||
{
|
||||
reference.Writer.TryWrite(item * i);
|
||||
channel.Writer.TryWrite(item * i);
|
||||
}
|
||||
|
||||
(await t1).Should().BeTrue();
|
||||
(await t2).Should().BeTrue();
|
||||
|
||||
foreach (var i in Enumerable.Range(1, 3))
|
||||
{
|
||||
(await reference.Reader.WaitToReadAsync()).Should().BeTrue();
|
||||
(await channel.Reader.WaitToReadAsync()).Should().BeTrue();
|
||||
|
||||
reference.Reader.TryRead(out var refitem).Should().BeTrue();
|
||||
channel.Reader.TryRead(out var chanitem).Should().BeTrue();
|
||||
refitem.Should().Be(item * i);
|
||||
chanitem.Should().Be(item * i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteOnEmpty()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
reference.Reader.TryRead(out var refitem);
|
||||
channel.Reader.TryRead(out var chanitem);
|
||||
}
|
||||
|
||||
// Empty.
|
||||
|
||||
var completion1 = reference.Reader.Completion;
|
||||
var wait1 = reference.Reader.WaitToReadAsync();
|
||||
|
||||
var completion2 = channel.Reader.Completion;
|
||||
var wait2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
reference.Writer.TryComplete();
|
||||
channel.Writer.TryComplete();
|
||||
|
||||
completion1.Status.Should().Be(TaskStatus.RanToCompletion);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Succeeded);
|
||||
|
||||
(await wait1).Should().BeFalse();
|
||||
(await wait2).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteErrorOnEmpty()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
reference.Reader.TryRead(out var refitem);
|
||||
channel.Reader.TryRead(out var chanitem);
|
||||
}
|
||||
|
||||
// Empty.
|
||||
|
||||
var completion1 = reference.Reader.Completion;
|
||||
var wait1 = reference.Reader.WaitToReadAsync();
|
||||
|
||||
var completion2 = channel.Reader.Completion;
|
||||
var wait2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
var ex = new Exception();
|
||||
reference.Writer.TryComplete(ex);
|
||||
channel.Writer.TryComplete(ex);
|
||||
|
||||
completion1.Status.Should().Be(TaskStatus.Faulted);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Faulted);
|
||||
|
||||
(await Assert.ThrowsAsync<Exception>(async () => await wait1)).Should().Be(ex);
|
||||
(await Assert.ThrowsAsync<Exception>(async () => await wait2)).Should().Be(ex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteWithRest()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
// Three Item2.
|
||||
|
||||
var completion1 = reference.Reader.Completion;
|
||||
var wait1 = reference.Reader.WaitToReadAsync();
|
||||
|
||||
var completion2 = channel.Reader.Completion;
|
||||
var wait2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
reference.Writer.TryComplete();
|
||||
channel.Writer.TryComplete();
|
||||
|
||||
// completion1.Status.Should().Be(TaskStatus.WaitingForActivation);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Pending);
|
||||
|
||||
(await wait1).Should().BeTrue();
|
||||
(await wait2).Should().BeTrue();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Reader.TryRead(out var i1).Should().BeTrue();
|
||||
channel.Reader.TryRead(out var i2).Should().BeTrue();
|
||||
i1.Should().Be(item);
|
||||
i2.Should().Be(item);
|
||||
}
|
||||
|
||||
(await reference.Reader.WaitToReadAsync()).Should().BeFalse();
|
||||
(await channel.Reader.WaitToReadAsync()).Should().BeFalse();
|
||||
|
||||
completion1.Status.Should().Be(TaskStatus.RanToCompletion);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Succeeded);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task CompleteErrorWithRest()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
// Three Item2.
|
||||
|
||||
var completion1 = reference.Reader.Completion;
|
||||
var wait1 = reference.Reader.WaitToReadAsync();
|
||||
|
||||
var completion2 = channel.Reader.Completion;
|
||||
var wait2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
var ex = new Exception();
|
||||
reference.Writer.TryComplete(ex);
|
||||
channel.Writer.TryComplete(ex);
|
||||
|
||||
// completion1.Status.Should().Be(TaskStatus.WaitingForActivation);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Pending);
|
||||
|
||||
(await wait1).Should().BeTrue();
|
||||
(await wait2).Should().BeTrue();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Reader.TryRead(out var i1).Should().BeTrue();
|
||||
channel.Reader.TryRead(out var i2).Should().BeTrue();
|
||||
i1.Should().Be(item);
|
||||
i2.Should().Be(item);
|
||||
}
|
||||
|
||||
wait1 = reference.Reader.WaitToReadAsync();
|
||||
wait2 = channel.Reader.WaitToReadAsync();
|
||||
|
||||
(await Assert.ThrowsAsync<Exception>(async () => await wait1)).Should().Be(ex);
|
||||
(await Assert.ThrowsAsync<Exception>(async () => await wait2)).Should().Be(ex);
|
||||
|
||||
completion1.Status.Should().Be(TaskStatus.Faulted);
|
||||
completion2.Status.Should().Be(UniTaskStatus.Faulted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Cancellation()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
var wait1 = reference.Reader.WaitToReadAsync(cts.Token);
|
||||
var wait2 = channel.Reader.WaitToReadAsync(cts.Token);
|
||||
|
||||
cts.Cancel();
|
||||
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await wait1)).CancellationToken.Should().Be(cts.Token);
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await wait2)).CancellationToken.Should().Be(cts.Token);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AsyncEnumerator()
|
||||
{
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var ta1 = reference.Reader.ReadAllAsync().ToArrayAsync();
|
||||
var ta2 = channel.Reader.ReadAllAsync().ToArrayAsync();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
reference.Writer.TryComplete();
|
||||
channel.Writer.TryComplete();
|
||||
|
||||
(await ta1).Should().BeEquivalentTo(new[] { 10, 20, 30 });
|
||||
(await ta2).Should().BeEquivalentTo(new[] { 10, 20, 30 });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task AsyncEnumeratorCancellation()
|
||||
{
|
||||
// Token1, Token2 and Cancel1
|
||||
{
|
||||
var cts1 = new CancellationTokenSource();
|
||||
var cts2 = new CancellationTokenSource();
|
||||
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var ta1 = reference.Reader.ReadAllAsync(cts1.Token).ToArrayAsync(cts2.Token);
|
||||
var ta2 = channel.Reader.ReadAllAsync(cts1.Token).ToArrayAsync(cts2.Token);
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
cts1.Cancel();
|
||||
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta1);
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta2)).CancellationToken.Should().Be(cts1.Token);
|
||||
}
|
||||
// Token1, Token2 and Cancel2
|
||||
{
|
||||
var cts1 = new CancellationTokenSource();
|
||||
var cts2 = new CancellationTokenSource();
|
||||
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var ta1 = reference.Reader.ReadAllAsync(cts1.Token).ToArrayAsync(cts2.Token);
|
||||
var ta2 = channel.Reader.ReadAllAsync(cts1.Token).ToArrayAsync(cts2.Token);
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
cts2.Cancel();
|
||||
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta1);
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta2)).CancellationToken.Should().Be(cts2.Token);
|
||||
}
|
||||
// Token1 and Cancel1
|
||||
{
|
||||
var cts1 = new CancellationTokenSource();
|
||||
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var ta1 = reference.Reader.ReadAllAsync(cts1.Token).ToArrayAsync();
|
||||
var ta2 = channel.Reader.ReadAllAsync(cts1.Token).ToArrayAsync();
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
cts1.Cancel();
|
||||
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta1);
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta2)).CancellationToken.Should().Be(cts1.Token);
|
||||
}
|
||||
// Token2 and Cancel2
|
||||
{
|
||||
var cts2 = new CancellationTokenSource();
|
||||
|
||||
var (reference, channel) = CreateChannel();
|
||||
|
||||
var ta1 = reference.Reader.ReadAllAsync().ToArrayAsync(cts2.Token);
|
||||
var ta2 = channel.Reader.ReadAllAsync().ToArrayAsync(cts2.Token);
|
||||
|
||||
foreach (var item in new[] { 10, 20, 30 })
|
||||
{
|
||||
reference.Writer.TryWrite(item);
|
||||
channel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
cts2.Cancel();
|
||||
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta1);
|
||||
(await Assert.ThrowsAsync<OperationCanceledException>(async () => await ta2)).CancellationToken.Should().Be(cts2.Token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
src/UniTask.NetCoreTests/DeferTest.cs
Normal file
47
src/UniTask.NetCoreTests/DeferTest.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Channels;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests
|
||||
{
|
||||
public class DeferTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task D()
|
||||
{
|
||||
var created = false;
|
||||
var v = UniTask.Defer(() => { created = true; return UniTask.Run(() => 10); });
|
||||
|
||||
created.Should().BeFalse();
|
||||
|
||||
var t = await v;
|
||||
|
||||
created.Should().BeTrue();
|
||||
|
||||
t.Should().Be(10);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task D2()
|
||||
{
|
||||
var created = false;
|
||||
var v = UniTask.Defer(() => { created = true; return UniTask.Run(() => 10).AsUniTask(); });
|
||||
|
||||
created.Should().BeFalse();
|
||||
|
||||
await v;
|
||||
|
||||
created.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace NetCoreTests.Linq
|
||||
xs.Should().Be(ys);
|
||||
}
|
||||
{
|
||||
var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAwaitCancellationAsync((x, _) => UniTask.Run(() => x));
|
||||
var xs = await UniTaskAsyncEnumerable.Range(start, count).SumAwaitWithCancellationAsync((x, _) => UniTask.Run(() => x));
|
||||
var ys = Enumerable.Range(start, count).Sum(x => x);
|
||||
xs.Should().Be(ys);
|
||||
}
|
||||
|
||||
@@ -319,5 +319,119 @@ namespace NetCoreTests.Linq
|
||||
await Assert.ThrowsAsync<UniTaskTestException>(async () => await ys);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CombineLatestOK()
|
||||
{
|
||||
var a = new AsyncReactiveProperty<int>(0);
|
||||
var b = new AsyncReactiveProperty<int>(0);
|
||||
|
||||
var list = new List<(int, int)>();
|
||||
var complete = a.WithoutCurrent().CombineLatest(b.WithoutCurrent(), (x, y) => (x, y)).ForEachAsync(x => list.Add(x));
|
||||
|
||||
list.Count.Should().Be(0);
|
||||
|
||||
a.Value = 10;
|
||||
list.Count.Should().Be(0);
|
||||
|
||||
a.Value = 20;
|
||||
list.Count.Should().Be(0);
|
||||
|
||||
b.Value = 1;
|
||||
list.Count.Should().Be(1);
|
||||
|
||||
list[0].Should().Be((20, 1));
|
||||
|
||||
a.Value = 30;
|
||||
list.Last().Should().Be((30, 1));
|
||||
|
||||
b.Value = 2;
|
||||
list.Last().Should().Be((30, 2));
|
||||
|
||||
a.Dispose();
|
||||
b.Value = 3;
|
||||
list.Last().Should().Be((30, 3));
|
||||
|
||||
b.Dispose();
|
||||
|
||||
await complete;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CombineLatestLong()
|
||||
{
|
||||
var a = UniTaskAsyncEnumerable.Range(1, 100000);
|
||||
var b = new AsyncReactiveProperty<int>(0);
|
||||
|
||||
var list = new List<(int, int)>();
|
||||
var complete = a.CombineLatest(b.WithoutCurrent(), (x, y) => (x, y)).ForEachAsync(x => list.Add(x));
|
||||
|
||||
b.Value = 1;
|
||||
|
||||
list[0].Should().Be((100000, 1));
|
||||
|
||||
b.Dispose();
|
||||
|
||||
await complete;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CombineLatestError()
|
||||
{
|
||||
var a = new AsyncReactiveProperty<int>(0);
|
||||
var b = new AsyncReactiveProperty<int>(0);
|
||||
|
||||
var list = new List<(int, int)>();
|
||||
var complete = a.WithoutCurrent()
|
||||
.Select(x => { if (x == 0) { throw new MyException(); } return x; })
|
||||
.CombineLatest(b.WithoutCurrent(), (x, y) => (x, y)).ForEachAsync(x => list.Add(x));
|
||||
|
||||
|
||||
a.Value = 10;
|
||||
b.Value = 1;
|
||||
list.Last().Should().Be((10, 1));
|
||||
|
||||
a.Value = 0;
|
||||
|
||||
await Assert.ThrowsAsync<MyException>(async () => await complete);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Fact]
|
||||
public async Task PariwiseImmediate()
|
||||
{
|
||||
var xs = await UniTaskAsyncEnumerable.Range(1, 5).Pairwise().ToArrayAsync();
|
||||
xs.Should().BeEquivalentTo((1, 2), (2, 3), (3, 4), (4, 5));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Pariwise()
|
||||
{
|
||||
var a = new AsyncReactiveProperty<int>(0);
|
||||
|
||||
var list = new List<(int, int)>();
|
||||
var complete = a.WithoutCurrent().Pairwise().ForEachAsync(x => list.Add(x));
|
||||
|
||||
list.Count.Should().Be(0);
|
||||
a.Value = 10;
|
||||
list.Count.Should().Be(0);
|
||||
a.Value = 20;
|
||||
list.Count.Should().Be(1);
|
||||
a.Value = 30;
|
||||
a.Value = 40;
|
||||
a.Value = 50;
|
||||
|
||||
a.Dispose();
|
||||
|
||||
await complete;
|
||||
|
||||
list.Should().BeEquivalentTo((10, 20), (20, 30), (30, 40), (40, 50));
|
||||
}
|
||||
|
||||
class MyException : Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
78
src/UniTask.NetCoreTests/Linq/PulbishTest.cs
Normal file
78
src/UniTask.NetCoreTests/Linq/PulbishTest.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests.Linq
|
||||
{
|
||||
public class PublishTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task Normal()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var multicast = rp.Publish();
|
||||
|
||||
var a = multicast.ToArrayAsync();
|
||||
var b = multicast.Take(2).ToArrayAsync();
|
||||
|
||||
var disp = multicast.Connect();
|
||||
|
||||
rp.Value = 2;
|
||||
|
||||
(await b).Should().BeEquivalentTo(1, 2);
|
||||
|
||||
var c = multicast.ToArrayAsync();
|
||||
|
||||
rp.Value = 3;
|
||||
rp.Value = 4;
|
||||
rp.Value = 5;
|
||||
|
||||
rp.Dispose();
|
||||
|
||||
(await a).Should().BeEquivalentTo(1, 2, 3, 4, 5);
|
||||
(await c).Should().BeEquivalentTo(3, 4, 5);
|
||||
|
||||
disp.Dispose();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Cancel()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var multicast = rp.Publish();
|
||||
|
||||
var a = multicast.ToArrayAsync();
|
||||
var b = multicast.Take(2).ToArrayAsync();
|
||||
|
||||
var disp = multicast.Connect();
|
||||
|
||||
rp.Value = 2;
|
||||
|
||||
(await b).Should().BeEquivalentTo(1, 2);
|
||||
|
||||
var c = multicast.ToArrayAsync();
|
||||
|
||||
rp.Value = 3;
|
||||
|
||||
disp.Dispose();
|
||||
|
||||
rp.Value = 4;
|
||||
rp.Value = 5;
|
||||
|
||||
rp.Dispose();
|
||||
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await a);
|
||||
await Assert.ThrowsAsync<OperationCanceledException>(async () => await c);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
29
src/UniTask.NetCoreTests/Linq/QueueTest.cs
Normal file
29
src/UniTask.NetCoreTests/Linq/QueueTest.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests.Linq
|
||||
{
|
||||
public class QueueTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task Q()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(100);
|
||||
|
||||
var l = new List<int>();
|
||||
await rp.Take(10).Queue().ForEachAsync(x =>
|
||||
{
|
||||
rp.Value += 10;
|
||||
l.Add(x);
|
||||
});
|
||||
|
||||
l.Should().BeEquivalentTo(100, 110, 120, 130, 140, 150, 160, 170, 180, 190);
|
||||
}
|
||||
}
|
||||
}
|
||||
106
src/UniTask.NetCoreTests/Linq/TakeInfinityTest.cs
Normal file
106
src/UniTask.NetCoreTests/Linq/TakeInfinityTest.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using FluentAssertions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace NetCoreTests.Linq
|
||||
{
|
||||
public class TakeInfinityTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task Take()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var xs = rp.Take(5).ToArrayAsync();
|
||||
|
||||
rp.Value = 2;
|
||||
rp.Value = 3;
|
||||
rp.Value = 4;
|
||||
rp.Value = 5;
|
||||
|
||||
(await xs).Should().BeEquivalentTo(1, 2, 3, 4, 5);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TakeWhile()
|
||||
{
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var xs = rp.TakeWhile(x => x != 5).ToArrayAsync();
|
||||
|
||||
rp.Value = 2;
|
||||
rp.Value = 3;
|
||||
rp.Value = 4;
|
||||
rp.Value = 5;
|
||||
|
||||
(await xs).Should().BeEquivalentTo(1, 2, 3, 4);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task TakeUntil()
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var xs = rp.TakeUntilCanceled(cts.Token).ToArrayAsync();
|
||||
|
||||
var c = CancelAsync();
|
||||
|
||||
await c;
|
||||
var foo = await xs;
|
||||
|
||||
foo.Should().BeEquivalentTo(new[] { 1, 10, 20 });
|
||||
|
||||
async Task CancelAsync()
|
||||
{
|
||||
rp.Value = 10;
|
||||
await Task.Yield();
|
||||
rp.Value = 20;
|
||||
await Task.Yield();
|
||||
cts.Cancel();
|
||||
rp.Value = 30;
|
||||
await Task.Yield();
|
||||
rp.Value = 40;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SkipUntil()
|
||||
{
|
||||
var cts = new CancellationTokenSource();
|
||||
|
||||
var rp = new AsyncReactiveProperty<int>(1);
|
||||
|
||||
var xs = rp.SkipUntilCanceled(cts.Token).ToArrayAsync();
|
||||
|
||||
var c = CancelAsync();
|
||||
|
||||
await c;
|
||||
var foo = await xs;
|
||||
|
||||
foo.Should().BeEquivalentTo(new[] { 30, 40 });
|
||||
|
||||
async Task CancelAsync()
|
||||
{
|
||||
rp.Value = 10;
|
||||
await Task.Yield();
|
||||
rp.Value = 20;
|
||||
await Task.Yield();
|
||||
cts.Cancel();
|
||||
rp.Value = 30;
|
||||
await Task.Yield();
|
||||
rp.Value = 40;
|
||||
|
||||
rp.Dispose(); // complete.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,371 @@
|
||||
using Cysharp.Threading.Tasks.Linq;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public interface IReadOnlyAsyncReactiveProperty<T> : IUniTaskAsyncEnumerable<T>
|
||||
{
|
||||
T Value { get; }
|
||||
IUniTaskAsyncEnumerable<T> WithoutCurrent();
|
||||
}
|
||||
|
||||
public interface IAsyncReactiveProperty<T> : IReadOnlyAsyncReactiveProperty<T>
|
||||
{
|
||||
new T Value { get; set; }
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class AsyncReactiveProperty<T> : IAsyncReactiveProperty<T>, IDisposable
|
||||
{
|
||||
TriggerEvent<T> triggerEvent;
|
||||
|
||||
#if UNITY_2018_3_OR_NEWER
|
||||
[UnityEngine.SerializeField]
|
||||
#endif
|
||||
T latestValue;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return latestValue;
|
||||
}
|
||||
set
|
||||
{
|
||||
this.latestValue = value;
|
||||
triggerEvent.SetResult(value);
|
||||
}
|
||||
}
|
||||
|
||||
public AsyncReactiveProperty(T value)
|
||||
{
|
||||
this.latestValue = value;
|
||||
this.triggerEvent = default;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerable<T> WithoutCurrent()
|
||||
{
|
||||
return new WithoutCurrentEnumerable(this);
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken)
|
||||
{
|
||||
return new Enumerator(this, cancellationToken, true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
triggerEvent.SetCompleted();
|
||||
}
|
||||
|
||||
public static implicit operator T(AsyncReactiveProperty<T> value)
|
||||
{
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (isValueType) return latestValue.ToString();
|
||||
return latestValue?.ToString();
|
||||
}
|
||||
|
||||
static bool isValueType;
|
||||
|
||||
static AsyncReactiveProperty()
|
||||
{
|
||||
isValueType = typeof(T).IsValueType;
|
||||
}
|
||||
|
||||
class WithoutCurrentEnumerable : IUniTaskAsyncEnumerable<T>
|
||||
{
|
||||
readonly AsyncReactiveProperty<T> parent;
|
||||
|
||||
public WithoutCurrentEnumerable(AsyncReactiveProperty<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(parent, cancellationToken, false);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<T>, ITriggerHandler<T>
|
||||
{
|
||||
static Action<object> cancellationCallback = CancellationCallback;
|
||||
|
||||
readonly AsyncReactiveProperty<T> parent;
|
||||
readonly CancellationToken cancellationToken;
|
||||
readonly CancellationTokenRegistration cancellationTokenRegistration;
|
||||
T value;
|
||||
bool isDisposed;
|
||||
bool firstCall;
|
||||
|
||||
public Enumerator(AsyncReactiveProperty<T> parent, CancellationToken cancellationToken, bool publishCurrentValue)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.firstCall = publishCurrentValue;
|
||||
|
||||
parent.triggerEvent.Add(this);
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
|
||||
if (cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this);
|
||||
}
|
||||
}
|
||||
|
||||
public T Current => value;
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// raise latest value on first call.
|
||||
if (firstCall)
|
||||
{
|
||||
firstCall = false;
|
||||
value = parent.Value;
|
||||
return CompletedTasks.True;
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
parent.triggerEvent.Remove(this);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public void OnNext(T value)
|
||||
{
|
||||
this.value = value;
|
||||
completionSource.TrySetResult(true);
|
||||
}
|
||||
|
||||
public void OnCanceled(CancellationToken cancellationToken)
|
||||
{
|
||||
DisposeAsync().Forget();
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
}
|
||||
|
||||
public void OnError(Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
|
||||
static void CancellationCallback(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
self.DisposeAsync().Forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ReadOnlyAsyncReactiveProperty<T> : IReadOnlyAsyncReactiveProperty<T>, IDisposable
|
||||
{
|
||||
TriggerEvent<T> triggerEvent;
|
||||
|
||||
T latestValue;
|
||||
IUniTaskAsyncEnumerator<T> enumerator;
|
||||
|
||||
public T Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return latestValue;
|
||||
}
|
||||
}
|
||||
|
||||
public ReadOnlyAsyncReactiveProperty(T initialValue, IUniTaskAsyncEnumerable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
latestValue = initialValue;
|
||||
ConsumeEnumerator(source, cancellationToken).Forget();
|
||||
}
|
||||
|
||||
public ReadOnlyAsyncReactiveProperty(IUniTaskAsyncEnumerable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
ConsumeEnumerator(source, cancellationToken).Forget();
|
||||
}
|
||||
|
||||
async UniTaskVoid ConsumeEnumerator(IUniTaskAsyncEnumerable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
enumerator = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
{
|
||||
while (await enumerator.MoveNextAsync())
|
||||
{
|
||||
var value = enumerator.Current;
|
||||
this.latestValue = value;
|
||||
triggerEvent.SetResult(value);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
await enumerator.DisposeAsync();
|
||||
enumerator = null;
|
||||
}
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerable<T> WithoutCurrent()
|
||||
{
|
||||
return new WithoutCurrentEnumerable(this);
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken)
|
||||
{
|
||||
return new Enumerator(this, cancellationToken, true);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (enumerator != null)
|
||||
{
|
||||
enumerator.DisposeAsync().Forget();
|
||||
}
|
||||
|
||||
triggerEvent.SetCompleted();
|
||||
}
|
||||
|
||||
public static implicit operator T(ReadOnlyAsyncReactiveProperty<T> value)
|
||||
{
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (isValueType) return latestValue.ToString();
|
||||
return latestValue?.ToString();
|
||||
}
|
||||
|
||||
static bool isValueType;
|
||||
|
||||
static ReadOnlyAsyncReactiveProperty()
|
||||
{
|
||||
isValueType = typeof(T).IsValueType;
|
||||
}
|
||||
|
||||
class WithoutCurrentEnumerable : IUniTaskAsyncEnumerable<T>
|
||||
{
|
||||
readonly ReadOnlyAsyncReactiveProperty<T> parent;
|
||||
|
||||
public WithoutCurrentEnumerable(ReadOnlyAsyncReactiveProperty<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(parent, cancellationToken, false);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<T>, ITriggerHandler<T>
|
||||
{
|
||||
static Action<object> cancellationCallback = CancellationCallback;
|
||||
|
||||
readonly ReadOnlyAsyncReactiveProperty<T> parent;
|
||||
readonly CancellationToken cancellationToken;
|
||||
readonly CancellationTokenRegistration cancellationTokenRegistration;
|
||||
T value;
|
||||
bool isDisposed;
|
||||
bool firstCall;
|
||||
|
||||
public Enumerator(ReadOnlyAsyncReactiveProperty<T> parent, CancellationToken cancellationToken, bool publishCurrentValue)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.firstCall = publishCurrentValue;
|
||||
|
||||
parent.triggerEvent.Add(this);
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
|
||||
if (cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationCallback, this);
|
||||
}
|
||||
}
|
||||
|
||||
public T Current => value;
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
// raise latest value on first call.
|
||||
if (firstCall)
|
||||
{
|
||||
firstCall = false;
|
||||
value = parent.Value;
|
||||
return CompletedTasks.True;
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
parent.triggerEvent.Remove(this);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public void OnNext(T value)
|
||||
{
|
||||
this.value = value;
|
||||
completionSource.TrySetResult(true);
|
||||
}
|
||||
|
||||
public void OnCanceled(CancellationToken cancellationToken)
|
||||
{
|
||||
DisposeAsync().Forget();
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
}
|
||||
|
||||
public void OnError(Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
|
||||
static void CancellationCallback(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
self.DisposeAsync().Forget();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class StateExtensions
|
||||
{
|
||||
public static ReadOnlyAsyncReactiveProperty<T> ToReadOnlyAsyncReactiveProperty<T>(this IUniTaskAsyncEnumerable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
return new ReadOnlyAsyncReactiveProperty<T>(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static ReadOnlyAsyncReactiveProperty<T> ToReadOnlyAsyncReactiveProperty<T>(this IUniTaskAsyncEnumerable<T> source, T initialValue, CancellationToken cancellationToken)
|
||||
{
|
||||
return new ReadOnlyAsyncReactiveProperty<T>(initialValue, source, cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ef320b87f537ee4fb2282e765dc6166
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
@@ -9,15 +10,15 @@ namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
static readonly Action<object> cancellationTokenCallback = Callback;
|
||||
|
||||
public static (UniTask, CancellationTokenRegistration) ToUniTask(this CancellationToken cts)
|
||||
public static (UniTask, CancellationTokenRegistration) ToUniTask(this CancellationToken cancellationToken)
|
||||
{
|
||||
if (cts.IsCancellationRequested)
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return (UniTask.FromCanceled(cts), default(CancellationTokenRegistration));
|
||||
return (UniTask.FromCanceled(cancellationToken), default(CancellationTokenRegistration));
|
||||
}
|
||||
|
||||
var promise = new UniTaskCompletionSource();
|
||||
return (promise.Task, cts.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
||||
return (promise.Task, cancellationToken.RegisterWithoutCaptureExecutionContext(cancellationTokenCallback, promise));
|
||||
}
|
||||
|
||||
static void Callback(object state)
|
||||
@@ -26,6 +27,11 @@ namespace Cysharp.Threading.Tasks
|
||||
promise.TrySetResult();
|
||||
}
|
||||
|
||||
public static CancellationTokenAwaitable WaitUntilCanceled(this CancellationToken cancellationToken)
|
||||
{
|
||||
return new CancellationTokenAwaitable(cancellationToken);
|
||||
}
|
||||
|
||||
public static CancellationTokenRegistration RegisterWithoutCaptureExecutionContext(this CancellationToken cancellationToken, Action callback)
|
||||
{
|
||||
var restoreFlow = false;
|
||||
@@ -70,5 +76,46 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct CancellationTokenAwaitable
|
||||
{
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public CancellationTokenAwaitable(CancellationToken cancellationToken)
|
||||
{
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public Awaiter GetAwaiter()
|
||||
{
|
||||
return new Awaiter(cancellationToken);
|
||||
}
|
||||
|
||||
public struct Awaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public Awaiter(CancellationToken cancellationToken)
|
||||
{
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public bool IsCompleted => !cancellationToken.CanBeCanceled || cancellationToken.IsCancellationRequested;
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnCompleted(Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(Action continuation)
|
||||
{
|
||||
cancellationToken.RegisterWithoutCaptureExecutionContext(continuation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
450
src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs
Normal file
450
src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs
Normal file
@@ -0,0 +1,450 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public static class Channel
|
||||
{
|
||||
public static Channel<T> CreateSingleConsumerUnbounded<T>()
|
||||
{
|
||||
return new SingleConsumerUnboundedChannel<T>();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Channel<TWrite, TRead>
|
||||
{
|
||||
public ChannelReader<TRead> Reader { get; protected set; }
|
||||
public ChannelWriter<TWrite> Writer { get; protected set; }
|
||||
|
||||
public static implicit operator ChannelReader<TRead>(Channel<TWrite, TRead> channel) => channel.Reader;
|
||||
public static implicit operator ChannelWriter<TWrite>(Channel<TWrite, TRead> channel) => channel.Writer;
|
||||
}
|
||||
|
||||
public abstract class Channel<T> : Channel<T, T>
|
||||
{
|
||||
}
|
||||
|
||||
public abstract class ChannelReader<T>
|
||||
{
|
||||
public abstract bool TryRead(out T item);
|
||||
public abstract UniTask<bool> WaitToReadAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
|
||||
public abstract UniTask Completion { get; }
|
||||
|
||||
public virtual UniTask<T> ReadAsync(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (this.TryRead(out var item))
|
||||
{
|
||||
return UniTask.FromResult(item);
|
||||
}
|
||||
|
||||
return ReadAsyncCore(cancellationToken);
|
||||
}
|
||||
|
||||
async UniTask<T> ReadAsyncCore(CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
if (await WaitToReadAsync(cancellationToken))
|
||||
{
|
||||
if (TryRead(out var item))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ChannelClosedException();
|
||||
}
|
||||
|
||||
public abstract IUniTaskAsyncEnumerable<T> ReadAllAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||
}
|
||||
|
||||
public abstract class ChannelWriter<T>
|
||||
{
|
||||
public abstract bool TryWrite(T item);
|
||||
public abstract bool TryComplete(Exception error = null);
|
||||
|
||||
public void Complete(Exception error = null)
|
||||
{
|
||||
if (!TryComplete(error))
|
||||
{
|
||||
throw new ChannelClosedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ChannelClosedException : InvalidOperationException
|
||||
{
|
||||
public ChannelClosedException() :
|
||||
base("Channel is already closed.")
|
||||
{ }
|
||||
|
||||
public ChannelClosedException(string message) : base(message) { }
|
||||
|
||||
public ChannelClosedException(Exception innerException) :
|
||||
base("Channel is already closed", innerException)
|
||||
{ }
|
||||
|
||||
public ChannelClosedException(string message, Exception innerException) : base(message, innerException) { }
|
||||
}
|
||||
|
||||
internal class SingleConsumerUnboundedChannel<T> : Channel<T>
|
||||
{
|
||||
readonly Queue<T> items;
|
||||
readonly SingleConsumerUnboundedChannelReader readerSource;
|
||||
UniTaskCompletionSource completedTaskSource;
|
||||
UniTask completedTask;
|
||||
|
||||
Exception completionError;
|
||||
bool closed;
|
||||
|
||||
public SingleConsumerUnboundedChannel()
|
||||
{
|
||||
items = new Queue<T>();
|
||||
Writer = new SingleConsumerUnboundedChannelWriter(this);
|
||||
readerSource = new SingleConsumerUnboundedChannelReader(this);
|
||||
Reader = readerSource;
|
||||
}
|
||||
|
||||
sealed class SingleConsumerUnboundedChannelWriter : ChannelWriter<T>
|
||||
{
|
||||
readonly SingleConsumerUnboundedChannel<T> parent;
|
||||
|
||||
public SingleConsumerUnboundedChannelWriter(SingleConsumerUnboundedChannel<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public override bool TryWrite(T item)
|
||||
{
|
||||
bool waiting;
|
||||
lock (parent.items)
|
||||
{
|
||||
if (parent.closed) return false;
|
||||
|
||||
parent.items.Enqueue(item);
|
||||
waiting = parent.readerSource.isWaiting;
|
||||
}
|
||||
|
||||
if (waiting)
|
||||
{
|
||||
parent.readerSource.SingalContinuation();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool TryComplete(Exception error = null)
|
||||
{
|
||||
bool waiting;
|
||||
lock (parent.items)
|
||||
{
|
||||
if (parent.closed) return false;
|
||||
parent.closed = true;
|
||||
waiting = parent.readerSource.isWaiting;
|
||||
|
||||
if (parent.items.Count == 0)
|
||||
{
|
||||
if (error == null)
|
||||
{
|
||||
if (parent.completedTaskSource != null)
|
||||
{
|
||||
parent.completedTaskSource.TrySetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.completedTask = UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent.completedTaskSource != null)
|
||||
{
|
||||
parent.completedTaskSource.TrySetException(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.completedTask = UniTask.FromException(error);
|
||||
}
|
||||
}
|
||||
|
||||
if (waiting)
|
||||
{
|
||||
parent.readerSource.SingalCompleted(error);
|
||||
}
|
||||
}
|
||||
|
||||
parent.completionError = error;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
sealed class SingleConsumerUnboundedChannelReader : ChannelReader<T>, IUniTaskSource<bool>
|
||||
{
|
||||
readonly Action<object> CancellationCallbackDelegate = CancellationCallback;
|
||||
readonly SingleConsumerUnboundedChannel<T> parent;
|
||||
|
||||
CancellationToken cancellationToken;
|
||||
CancellationTokenRegistration cancellationTokenRegistration;
|
||||
UniTaskCompletionSourceCore<bool> core;
|
||||
internal bool isWaiting;
|
||||
|
||||
public SingleConsumerUnboundedChannelReader(SingleConsumerUnboundedChannel<T> parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 4);
|
||||
}
|
||||
|
||||
public override UniTask Completion
|
||||
{
|
||||
get
|
||||
{
|
||||
if (parent.completedTaskSource != null) return parent.completedTaskSource.Task;
|
||||
|
||||
if (parent.closed)
|
||||
{
|
||||
return parent.completedTask;
|
||||
}
|
||||
|
||||
parent.completedTaskSource = new UniTaskCompletionSource();
|
||||
return parent.completedTaskSource.Task;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryRead(out T item)
|
||||
{
|
||||
lock (parent.items)
|
||||
{
|
||||
if (parent.items.Count != 0)
|
||||
{
|
||||
item = parent.items.Dequeue();
|
||||
|
||||
// complete when all value was consumed.
|
||||
if (parent.closed && parent.items.Count == 0)
|
||||
{
|
||||
if (parent.completionError != null)
|
||||
{
|
||||
if (parent.completedTaskSource != null)
|
||||
{
|
||||
parent.completedTaskSource.TrySetException(parent.completionError);
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.completedTask = UniTask.FromException(parent.completionError);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (parent.completedTaskSource != null)
|
||||
{
|
||||
parent.completedTaskSource.TrySetResult();
|
||||
}
|
||||
else
|
||||
{
|
||||
parent.completedTask = UniTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
item = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override UniTask<bool> WaitToReadAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return UniTask.FromCanceled<bool>(cancellationToken);
|
||||
}
|
||||
|
||||
lock (parent.items)
|
||||
{
|
||||
if (parent.items.Count != 0)
|
||||
{
|
||||
return CompletedTasks.True;
|
||||
}
|
||||
|
||||
if (parent.closed)
|
||||
{
|
||||
if (parent.completionError == null)
|
||||
{
|
||||
return CompletedTasks.False;
|
||||
}
|
||||
else
|
||||
{
|
||||
return UniTask.FromException<bool>(parent.completionError);
|
||||
}
|
||||
}
|
||||
|
||||
cancellationTokenRegistration.Dispose();
|
||||
|
||||
core.Reset();
|
||||
isWaiting = true;
|
||||
|
||||
this.cancellationToken = cancellationToken;
|
||||
if (this.cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = this.cancellationToken.RegisterWithoutCaptureExecutionContext(CancellationCallbackDelegate, this);
|
||||
}
|
||||
|
||||
return new UniTask<bool>(this, core.Version);
|
||||
}
|
||||
}
|
||||
|
||||
public void SingalContinuation()
|
||||
{
|
||||
core.TrySetResult(true);
|
||||
}
|
||||
|
||||
public void SingalCancellation(CancellationToken cancellationToken)
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
|
||||
public void SingalCompleted(Exception error)
|
||||
{
|
||||
if (error != null)
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
core.TrySetException(error);
|
||||
}
|
||||
else
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
core.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
public override IUniTaskAsyncEnumerable<T> ReadAllAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new ReadAllAsyncEnumerable(this, cancellationToken);
|
||||
}
|
||||
|
||||
bool IUniTaskSource<bool>.GetResult(short token)
|
||||
{
|
||||
return core.GetResult(token);
|
||||
}
|
||||
|
||||
void IUniTaskSource.GetResult(short token)
|
||||
{
|
||||
core.GetResult(token);
|
||||
}
|
||||
|
||||
UniTaskStatus IUniTaskSource.GetStatus(short token)
|
||||
{
|
||||
return core.GetStatus(token);
|
||||
}
|
||||
|
||||
void IUniTaskSource.OnCompleted(Action<object> continuation, object state, short token)
|
||||
{
|
||||
core.OnCompleted(continuation, state, token);
|
||||
}
|
||||
|
||||
UniTaskStatus IUniTaskSource.UnsafeGetStatus()
|
||||
{
|
||||
return core.UnsafeGetStatus();
|
||||
}
|
||||
|
||||
static void CancellationCallback(object state)
|
||||
{
|
||||
var self = (SingleConsumerUnboundedChannelReader)state;
|
||||
self.SingalCancellation(self.cancellationToken);
|
||||
}
|
||||
|
||||
sealed class ReadAllAsyncEnumerable : IUniTaskAsyncEnumerable<T>, IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
readonly Action<object> CancellationCallback1Delegate = CancellationCallback1;
|
||||
readonly Action<object> CancellationCallback2Delegate = CancellationCallback2;
|
||||
|
||||
readonly SingleConsumerUnboundedChannelReader parent;
|
||||
CancellationToken cancellationToken1;
|
||||
CancellationToken cancellationToken2;
|
||||
CancellationTokenRegistration CancellationTokenRegistration1;
|
||||
CancellationTokenRegistration CancellationTokenRegistration2;
|
||||
|
||||
T current;
|
||||
bool cacheValue;
|
||||
bool running;
|
||||
|
||||
public ReadAllAsyncEnumerable(SingleConsumerUnboundedChannelReader parent, CancellationToken cancellationToken)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.cancellationToken1 = cancellationToken;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (running)
|
||||
{
|
||||
throw new InvalidOperationException("Enumerator is already running, does not allow call GetAsyncEnumerator twice.");
|
||||
}
|
||||
|
||||
if (this.cancellationToken1 != cancellationToken)
|
||||
{
|
||||
this.cancellationToken2 = cancellationToken;
|
||||
}
|
||||
|
||||
if (this.cancellationToken1.CanBeCanceled)
|
||||
{
|
||||
this.cancellationToken1.RegisterWithoutCaptureExecutionContext(CancellationCallback1Delegate, this);
|
||||
}
|
||||
|
||||
if (this.cancellationToken2.CanBeCanceled)
|
||||
{
|
||||
this.cancellationToken2.RegisterWithoutCaptureExecutionContext(CancellationCallback2Delegate, this);
|
||||
}
|
||||
|
||||
running = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public T Current
|
||||
{
|
||||
get
|
||||
{
|
||||
if (cacheValue)
|
||||
{
|
||||
return current;
|
||||
}
|
||||
parent.TryRead(out current);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
cacheValue = false;
|
||||
return parent.WaitToReadAsync(CancellationToken.None); // ok to use None, registered in ctor.
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
CancellationTokenRegistration1.Dispose();
|
||||
CancellationTokenRegistration2.Dispose();
|
||||
return default;
|
||||
}
|
||||
|
||||
static void CancellationCallback1(object state)
|
||||
{
|
||||
var self = (ReadAllAsyncEnumerable)state;
|
||||
self.parent.SingalCancellation(self.cancellationToken1);
|
||||
}
|
||||
|
||||
static void CancellationCallback2(object state)
|
||||
{
|
||||
var self = (ReadAllAsyncEnumerable)state;
|
||||
self.parent.SingalCancellation(self.cancellationToken2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs.meta
Normal file
11
src/UniTask/Assets/Plugins/UniTask/Runtime/Channel.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ceb3107bbdd1f14eb39091273798360
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -14,16 +14,19 @@ namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public static UniTask.Awaiter GetAwaiter(this IEnumerator enumerator)
|
||||
{
|
||||
Error.ThrowArgumentNullException(enumerator, nameof(enumerator));
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token).GetAwaiter();
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this IEnumerator enumerator)
|
||||
public static UniTask WithCancellation(this IEnumerator enumerator, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, CancellationToken.None, out var token), token);
|
||||
Error.ThrowArgumentNullException(enumerator, nameof(enumerator));
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, PlayerLoopTiming.Update, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
public static UniTask ToUniTask(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
Error.ThrowArgumentNullException(enumerator, nameof(enumerator));
|
||||
return new UniTask(EnumeratorPromise.Create(enumerator, timing, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,21 +13,23 @@ namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
public static class AddressableAsyncExtensions
|
||||
{
|
||||
#region AsyncOperationHandle
|
||||
#region AsyncOperationHandle
|
||||
|
||||
public static AsyncOperationHandleAwaiter GetAwaiter(this AsyncOperationHandle handle)
|
||||
{
|
||||
return new AsyncOperationHandleAwaiter(handle);
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this AsyncOperationHandle handle)
|
||||
public static UniTask WithCancellation(this AsyncOperationHandle handle, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token);
|
||||
if (handle.IsDone) return UniTask.CompletedTask;
|
||||
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, PlayerLoopTiming.Update, null, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask ConfigureAwait(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
public static UniTask ToUniTask(this AsyncOperationHandle handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
|
||||
{
|
||||
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellation, out var token), token);
|
||||
if (handle.IsDone) return UniTask.CompletedTask;
|
||||
return new UniTask(AsyncOperationHandleConfiguredSource.Create(handle, timing, progress, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public struct AsyncOperationHandleAwaiter : ICriticalNotifyCompletion
|
||||
@@ -75,7 +77,7 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class AsyncOperationHandleConfiguredSource : IUniTaskSource, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<AsyncOperationHandleConfiguredSource> pool = new PromisePool<AsyncOperationHandleConfiguredSource>();
|
||||
|
||||
@@ -185,22 +187,24 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region AsyncOperationHandle_T
|
||||
#region AsyncOperationHandle_T
|
||||
|
||||
public static AsyncOperationHandleAwaiter<T> GetAwaiter<T>(this AsyncOperationHandle<T> handle)
|
||||
{
|
||||
return new AsyncOperationHandleAwaiter<T>(handle);
|
||||
}
|
||||
|
||||
public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle)
|
||||
public static UniTask<T> WithCancellation<T>(this AsyncOperationHandle<T> handle, CancellationToken cancellationToken)
|
||||
{
|
||||
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, PlayerLoopTiming.Update, null, CancellationToken.None, out var token), token);
|
||||
if (handle.IsDone) return UniTask.FromResult(handle.Result);
|
||||
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, PlayerLoopTiming.Update, null, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask<T> ConfigureAwait<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
public static UniTask<T> ToUniTask<T>(this AsyncOperationHandle<T> handle, IProgress<float> progress = null, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellation = default(CancellationToken))
|
||||
{
|
||||
if (handle.IsDone) return UniTask.FromResult(handle.Result);
|
||||
return new UniTask<T>(AsyncOperationHandleConfiguredSource<T>.Create(handle, timing, progress, cancellation, out var token), token);
|
||||
}
|
||||
|
||||
@@ -250,7 +254,7 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, IPromisePoolItem
|
||||
sealed class AsyncOperationHandleConfiguredSource<T> : IUniTaskSource<T>, IPlayerLoopItem, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<AsyncOperationHandleConfiguredSource<T>> pool = new PromisePool<AsyncOperationHandleConfiguredSource<T>>();
|
||||
|
||||
@@ -366,7 +370,7 @@ namespace Cysharp.Threading.Tasks
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
245
src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs
vendored
Normal file
245
src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs
vendored
Normal file
@@ -0,0 +1,245 @@
|
||||
// asmdef Version Defines, enabled when com.demigiant.dotween is imported.
|
||||
|
||||
#if UNITASK_DOTWEEN_SUPPORT
|
||||
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks
|
||||
{
|
||||
// The idea of TweenCancelBehaviour is borrowed from https://www.shibuya24.info/entry/dotween_async_await
|
||||
public enum TweenCancelBehaviour
|
||||
{
|
||||
Kill,
|
||||
KillWithCompleteCallback,
|
||||
Complete,
|
||||
CompleteWithSeqeunceCallback,
|
||||
CancelAwait,
|
||||
|
||||
// AndCancelAwait
|
||||
KillAndCancelAwait,
|
||||
KillWithCompleteCallbackAndCancelAwait,
|
||||
CompleteAndCancelAwait,
|
||||
CompleteWithSeqeunceCallbackAndCancelAwait
|
||||
}
|
||||
|
||||
public static class DOTweenAsyncExtensions
|
||||
{
|
||||
public static TweenAwaiter GetAwaiter(this Tween tween)
|
||||
{
|
||||
return new TweenAwaiter(tween);
|
||||
}
|
||||
|
||||
public static UniTask WithCancellation(this Tween tween, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(tween, nameof(tween));
|
||||
|
||||
if (!tween.IsActive()) return UniTask.CompletedTask;
|
||||
return new UniTask(TweenConfiguredSource.Create(tween, TweenCancelBehaviour.Kill, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public static UniTask ToUniTask(this Tween tween, TweenCancelBehaviour tweenCancelBehaviour = TweenCancelBehaviour.Kill, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(tween, nameof(tween));
|
||||
|
||||
if (!tween.IsActive()) return UniTask.CompletedTask;
|
||||
return new UniTask(TweenConfiguredSource.Create(tween, tweenCancelBehaviour, cancellationToken, out var token), token);
|
||||
}
|
||||
|
||||
public struct TweenAwaiter : ICriticalNotifyCompletion
|
||||
{
|
||||
readonly Tween tween;
|
||||
|
||||
// killed(non active) as completed.
|
||||
public bool IsCompleted => !tween.IsActive();
|
||||
|
||||
public TweenAwaiter(Tween tween)
|
||||
{
|
||||
this.tween = tween;
|
||||
}
|
||||
|
||||
public TweenAwaiter GetAwaiter()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public void GetResult()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnCompleted(System.Action continuation)
|
||||
{
|
||||
UnsafeOnCompleted(continuation);
|
||||
}
|
||||
|
||||
public void UnsafeOnCompleted(System.Action continuation)
|
||||
{
|
||||
// convert Action -> TweenCallback allocation.
|
||||
// onKill is called after OnCompleted, both Complete(false/true) and Kill(false/true).
|
||||
tween.onKill = new TweenCallback(continuation);
|
||||
}
|
||||
}
|
||||
|
||||
sealed class TweenConfiguredSource : IUniTaskSource, IPromisePoolItem
|
||||
{
|
||||
static readonly PromisePool<TweenConfiguredSource> pool = new PromisePool<TweenConfiguredSource>();
|
||||
static Action<object> CancellationCallbackDelegate = CancellationCallback;
|
||||
|
||||
Tween tween;
|
||||
TweenCancelBehaviour cancelBehaviour;
|
||||
CancellationToken cancellationToken;
|
||||
bool canceled;
|
||||
|
||||
CancellationTokenRegistration cancellationTokenRegistration;
|
||||
UniTaskCompletionSourceCore<AsyncUnit> core;
|
||||
|
||||
TweenConfiguredSource()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static IUniTaskSource Create(Tween tween, TweenCancelBehaviour cancelBehaviour, CancellationToken cancellationToken, out short token)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return AutoResetUniTaskCompletionSource.CreateFromCanceled(cancellationToken, out token);
|
||||
}
|
||||
|
||||
var result = pool.TryRent() ?? new TweenConfiguredSource();
|
||||
|
||||
result.tween = tween;
|
||||
result.cancelBehaviour = cancelBehaviour;
|
||||
result.cancellationToken = cancellationToken;
|
||||
|
||||
TaskTracker.TrackActiveTask(result, 3);
|
||||
|
||||
result.RegisterEvent();
|
||||
|
||||
token = result.core.Version;
|
||||
return result;
|
||||
}
|
||||
|
||||
void RegisterEvent()
|
||||
{
|
||||
if (cancellationToken.CanBeCanceled)
|
||||
{
|
||||
cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(CancellationCallbackDelegate, this);
|
||||
}
|
||||
|
||||
// allocate delegate.
|
||||
tween.OnKill(new TweenCallback(OnKill));
|
||||
}
|
||||
|
||||
void OnKill()
|
||||
{
|
||||
cancellationTokenRegistration.Dispose();
|
||||
if (canceled)
|
||||
{
|
||||
if (cancelBehaviour == TweenCancelBehaviour.CancelAwait)
|
||||
{
|
||||
// already called TrySetCanceled, do nothing.
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
core.TrySetResult(AsyncUnit.Default);
|
||||
}
|
||||
}
|
||||
|
||||
static void CancellationCallback(object state)
|
||||
{
|
||||
var self = (TweenConfiguredSource)state;
|
||||
|
||||
switch (self.cancelBehaviour)
|
||||
{
|
||||
case TweenCancelBehaviour.Kill:
|
||||
default:
|
||||
self.tween.Kill(false);
|
||||
break;
|
||||
case TweenCancelBehaviour.KillAndCancelAwait:
|
||||
self.canceled = true;
|
||||
self.tween.Kill(false);
|
||||
break;
|
||||
case TweenCancelBehaviour.KillWithCompleteCallback:
|
||||
self.tween.Kill(true);
|
||||
break;
|
||||
case TweenCancelBehaviour.KillWithCompleteCallbackAndCancelAwait:
|
||||
self.canceled = true;
|
||||
self.tween.Kill(true);
|
||||
break;
|
||||
case TweenCancelBehaviour.Complete:
|
||||
self.tween.Complete(false);
|
||||
break;
|
||||
case TweenCancelBehaviour.CompleteAndCancelAwait:
|
||||
self.canceled = true;
|
||||
self.tween.Complete(false);
|
||||
break;
|
||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallback:
|
||||
self.tween.Complete(true);
|
||||
break;
|
||||
case TweenCancelBehaviour.CompleteWithSeqeunceCallbackAndCancelAwait:
|
||||
self.canceled = true;
|
||||
self.tween.Complete(true);
|
||||
break;
|
||||
case TweenCancelBehaviour.CancelAwait:
|
||||
self.canceled = true;
|
||||
self.core.TrySetCanceled(self.cancellationToken);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetResult(short token)
|
||||
{
|
||||
try
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
core.GetResult(token);
|
||||
}
|
||||
finally
|
||||
{
|
||||
pool.TryReturn(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 void Reset()
|
||||
{
|
||||
core.Reset();
|
||||
tween = default;
|
||||
cancellationToken = default;
|
||||
}
|
||||
|
||||
~TweenConfiguredSource()
|
||||
{
|
||||
if (pool.TryReturn(this))
|
||||
{
|
||||
GC.ReRegisterForFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
11
src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs.meta
vendored
Normal file
11
src/UniTask/Assets/Plugins/UniTask/Runtime/External/DoTweenAsyncExtensions.cs.meta
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f448d5bc5b232e4f98d89d5d1832e8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,6 +28,12 @@ namespace Cysharp.Threading.Tasks
|
||||
IUniTaskOrderedAsyncEnumerable<TElement> CreateOrderedEnumerable<TKey>(Func<TElement, CancellationToken, UniTask<TKey>> keySelector, IComparer<TKey> comparer, bool descending);
|
||||
}
|
||||
|
||||
public interface IConnectableUniTaskAsyncEnumerable<out T> : IUniTaskAsyncEnumerable<T>
|
||||
{
|
||||
IDisposable Connect();
|
||||
}
|
||||
|
||||
// don't use AsyncGrouping.
|
||||
//public interface IUniTaskAsyncGrouping<out TKey, out TElement> : IUniTaskAsyncEnumerable<TElement>
|
||||
//{
|
||||
// TKey Key { get; }
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
{
|
||||
const int MaxArrayLength = 0X7FEFFFFF;
|
||||
const int InitialSize = 16;
|
||||
|
||||
readonly PlayerLoopTiming timing;
|
||||
|
||||
SpinLock gate = new SpinLock();
|
||||
bool dequing = false;
|
||||
@@ -19,6 +21,11 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
int waitingListCount = 0;
|
||||
Action[] waitingList = new Action[InitialSize];
|
||||
|
||||
public ContinuationQueue(PlayerLoopTiming timing)
|
||||
{
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public void Enqueue(Action continuation)
|
||||
{
|
||||
bool lockTaken = false;
|
||||
@@ -72,7 +79,80 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
waitingList = new Action[InitialSize];
|
||||
}
|
||||
|
||||
// delegate entrypoint.
|
||||
public void Run()
|
||||
{
|
||||
// for debugging, create named stacktrace.
|
||||
#if DEBUG
|
||||
switch (timing)
|
||||
{
|
||||
case PlayerLoopTiming.Initialization:
|
||||
Initialization();
|
||||
break;
|
||||
case PlayerLoopTiming.LastInitialization:
|
||||
LastInitialization();
|
||||
break;
|
||||
case PlayerLoopTiming.EarlyUpdate:
|
||||
EarlyUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastEarlyUpdate:
|
||||
LastEarlyUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.FixedUpdate:
|
||||
FixedUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastFixedUpdate:
|
||||
LastFixedUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PreUpdate:
|
||||
PreUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPreUpdate:
|
||||
LastPreUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.Update:
|
||||
Update();
|
||||
break;
|
||||
case PlayerLoopTiming.LastUpdate:
|
||||
LastUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PreLateUpdate:
|
||||
PreLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPreLateUpdate:
|
||||
LastPreLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PostLateUpdate:
|
||||
PostLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPostLateUpdate:
|
||||
LastPostLateUpdate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
RunCore();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Initialization() => RunCore();
|
||||
void LastInitialization() => RunCore();
|
||||
void EarlyUpdate() => RunCore();
|
||||
void LastEarlyUpdate() => RunCore();
|
||||
void FixedUpdate() => RunCore();
|
||||
void LastFixedUpdate() => RunCore();
|
||||
void PreUpdate() => RunCore();
|
||||
void LastPreUpdate() => RunCore();
|
||||
void Update() => RunCore();
|
||||
void LastUpdate() => RunCore();
|
||||
void PreLateUpdate() => RunCore();
|
||||
void LastPreLateUpdate() => RunCore();
|
||||
void PostLateUpdate() => RunCore();
|
||||
void LastPostLateUpdate() => RunCore();
|
||||
|
||||
[System.Diagnostics.DebuggerHidden]
|
||||
void RunCore()
|
||||
{
|
||||
{
|
||||
bool lockTaken = false;
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
{
|
||||
const int InitialSize = 16;
|
||||
|
||||
readonly PlayerLoopTiming timing;
|
||||
readonly object runningAndQueueLock = new object();
|
||||
readonly object arrayLock = new object();
|
||||
readonly Action<Exception> unhandledExceptionCallback;
|
||||
@@ -17,9 +18,12 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
IPlayerLoopItem[] loopItems = new IPlayerLoopItem[InitialSize];
|
||||
MinimumQueue<IPlayerLoopItem> waitQueue = new MinimumQueue<IPlayerLoopItem>(InitialSize);
|
||||
|
||||
public PlayerLoopRunner()
|
||||
|
||||
|
||||
public PlayerLoopRunner(PlayerLoopTiming timing)
|
||||
{
|
||||
this.unhandledExceptionCallback = ex => Debug.LogException(ex);
|
||||
this.timing = timing;
|
||||
}
|
||||
|
||||
public void AddAction(IPlayerLoopItem item)
|
||||
@@ -55,7 +59,80 @@ namespace Cysharp.Threading.Tasks.Internal
|
||||
}
|
||||
}
|
||||
|
||||
// delegate entrypoint.
|
||||
public void Run()
|
||||
{
|
||||
// for debugging, create named stacktrace.
|
||||
#if DEBUG
|
||||
switch (timing)
|
||||
{
|
||||
case PlayerLoopTiming.Initialization:
|
||||
Initialization();
|
||||
break;
|
||||
case PlayerLoopTiming.LastInitialization:
|
||||
LastInitialization();
|
||||
break;
|
||||
case PlayerLoopTiming.EarlyUpdate:
|
||||
EarlyUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastEarlyUpdate:
|
||||
LastEarlyUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.FixedUpdate:
|
||||
FixedUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastFixedUpdate:
|
||||
LastFixedUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PreUpdate:
|
||||
PreUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPreUpdate:
|
||||
LastPreUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.Update:
|
||||
Update();
|
||||
break;
|
||||
case PlayerLoopTiming.LastUpdate:
|
||||
LastUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PreLateUpdate:
|
||||
PreLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPreLateUpdate:
|
||||
LastPreLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.PostLateUpdate:
|
||||
PostLateUpdate();
|
||||
break;
|
||||
case PlayerLoopTiming.LastPostLateUpdate:
|
||||
LastPostLateUpdate();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#else
|
||||
RunCore();
|
||||
#endif
|
||||
}
|
||||
|
||||
void Initialization() => RunCore();
|
||||
void LastInitialization() => RunCore();
|
||||
void EarlyUpdate() => RunCore();
|
||||
void LastEarlyUpdate() => RunCore();
|
||||
void FixedUpdate() => RunCore();
|
||||
void LastFixedUpdate() => RunCore();
|
||||
void PreUpdate() => RunCore();
|
||||
void LastPreUpdate() => RunCore();
|
||||
void Update() => RunCore();
|
||||
void LastUpdate() => RunCore();
|
||||
void PreLateUpdate() => RunCore();
|
||||
void LastPreLateUpdate() => RunCore();
|
||||
void PostLateUpdate() => RunCore();
|
||||
void LastPostLateUpdate() => RunCore();
|
||||
|
||||
[System.Diagnostics.DebuggerHidden]
|
||||
void RunCore()
|
||||
{
|
||||
lock (runningAndQueueLock)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAsync(source, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TAccumulate> AggregateAsync<TSource, TAccumulate>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, CancellationToken cancellationToken = default)
|
||||
@@ -20,7 +20,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAsync(source, seed, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> AggregateAsync<TSource, TAccumulate, TResult>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken = default)
|
||||
@@ -29,7 +29,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(resultSelector));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
return Aggregate.AggregateAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> AggregateAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, UniTask<TSource>> accumulator, CancellationToken cancellationToken = default)
|
||||
@@ -37,7 +37,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAwaitAsync(source, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TAccumulate> AggregateAwaitAsync<TSource, TAccumulate>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
|
||||
@@ -45,7 +45,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAwaitAsync(source, seed, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> AggregateAwaitAsync<TSource, TAccumulate, TResult>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, Func<TAccumulate, UniTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
|
||||
@@ -54,7 +54,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(resultSelector));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
return Aggregate.AggregateAwaitAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> AggregateAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, UniTask<TSource>> accumulator, CancellationToken cancellationToken = default)
|
||||
@@ -62,7 +62,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAwaitWithCancellationAsync(source, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TAccumulate> AggregateAwaitWithCancellationAsync<TSource, TAccumulate>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken = default)
|
||||
@@ -70,7 +70,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, cancellationToken);
|
||||
return Aggregate.AggregateAwaitWithCancellationAsync(source, seed, accumulator, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> AggregateAwaitWithCancellationAsync<TSource, TAccumulate, TResult>(this IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, Func<TAccumulate, CancellationToken, UniTask<TResult>> resultSelector, CancellationToken cancellationToken = default)
|
||||
@@ -79,13 +79,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(accumulator));
|
||||
Error.ThrowArgumentNullException(accumulator, nameof(resultSelector));
|
||||
|
||||
return Aggregate.InvokeAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
return Aggregate.AggregateAwaitWithCancellationAsync(source, seed, accumulator, resultSelector, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Aggregate
|
||||
{
|
||||
internal static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TSource> AggregateAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -116,7 +116,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TAccumulate> InvokeAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TAccumulate> AggregateAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -138,7 +138,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TResult> InvokeAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TResult> AggregateAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -162,7 +162,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with async
|
||||
|
||||
internal static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, UniTask<TSource>> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TSource> AggregateAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, UniTask<TSource>> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -193,7 +193,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TAccumulate> InvokeAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TAccumulate> AggregateAwaitAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -215,7 +215,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TResult> InvokeAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, Func<TAccumulate, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TResult> AggregateAwaitAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, UniTask<TAccumulate>> accumulator, Func<TAccumulate, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -240,7 +240,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with cancellation
|
||||
|
||||
internal static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, UniTask<TSource>> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TSource> AggregateAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TSource, CancellationToken, UniTask<TSource>> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -271,7 +271,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TAccumulate> InvokeAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TAccumulate> AggregateAwaitWithCancellationAsync<TSource, TAccumulate>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -293,7 +293,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<TResult> InvokeAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, Func<TAccumulate, CancellationToken, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TResult> AggregateAwaitWithCancellationAsync<TSource, TAccumulate, TResult>(IUniTaskAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, CancellationToken, UniTask<TAccumulate>> accumulator, Func<TAccumulate, CancellationToken, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return All.InvokeAsync(source, predicate, cancellationToken);
|
||||
return All.AllAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Boolean> AllAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -19,7 +19,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return All.InvokeAsync(source, predicate, cancellationToken);
|
||||
return All.AllAwaitAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Boolean> AllAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -27,13 +27,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return All.InvokeAsync(source, predicate, cancellationToken);
|
||||
return All.AllAwaitWithCancellationAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class All
|
||||
{
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AllAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AllAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -81,7 +81,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AllAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Any.InvokeAsync(source, cancellationToken);
|
||||
return Any.AnyAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Boolean> AnyAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Any.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Any.AnyAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Boolean> AnyAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Any.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Any.AnyAwaitAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Boolean> AnyAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,13 +34,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Any.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Any.AnyAwaitWithCancellationAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Any
|
||||
{
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AnyAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -61,7 +61,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AnyAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -85,7 +85,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AnyAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -109,7 +109,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> AnyAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -36,10 +36,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, element, append, cancellationToken);
|
||||
return new _AppendPrepend(source, element, append, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _AppendPrepend : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
enum State : byte
|
||||
{
|
||||
@@ -59,12 +59,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, TSource element, bool append, CancellationToken cancellationToken)
|
||||
public _AppendPrepend(IUniTaskAsyncEnumerable<TSource> source, TSource element, bool append, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.element = element;
|
||||
this.state = append ? State.RequireAppend : State.RequirePrepend;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -108,7 +110,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_AppendPrepend)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -136,6 +138,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -76,6 +76,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 4);
|
||||
}
|
||||
|
||||
// abstract
|
||||
@@ -178,6 +179,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
// if require additional resource to dispose, override and call base.DisposeAsync.
|
||||
public virtual UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
@@ -204,6 +206,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 4);
|
||||
}
|
||||
|
||||
// abstract
|
||||
@@ -399,6 +402,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
// if require additional resource to dispose, override and call base.DisposeAsync.
|
||||
public virtual UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -26,22 +26,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAsync(this IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken = default)
|
||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -57,22 +57,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float> AverageAsync(this IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken = default)
|
||||
@@ -80,7 +80,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -88,22 +88,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<float> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAsync(this IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken = default)
|
||||
@@ -111,7 +111,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -119,22 +119,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal> AverageAsync(this IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken = default)
|
||||
@@ -142,7 +142,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -150,22 +150,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<decimal> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync(this IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -173,7 +173,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -181,22 +181,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync(this IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -204,7 +204,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -212,22 +212,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float?> AverageAsync(this IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float?> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -235,7 +235,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float?> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -243,22 +243,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<float?> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<float?> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync(this IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -266,7 +266,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -274,22 +274,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<double?> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal?> AverageAsync(this IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal?> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -297,7 +297,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal?> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -305,22 +305,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<decimal?> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<decimal?> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static class Average
|
||||
{
|
||||
public static async UniTask<double> InvokeAsync(IUniTaskAsyncEnumerable<Int32> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync(IUniTaskAsyncEnumerable<Int32> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32 sum = 0;
|
||||
@@ -348,7 +348,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32 sum = 0;
|
||||
@@ -376,7 +376,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32 sum = 0;
|
||||
@@ -404,7 +404,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32 sum = 0;
|
||||
@@ -432,7 +432,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync(IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync(IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64 sum = 0;
|
||||
@@ -460,7 +460,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64 sum = 0;
|
||||
@@ -488,7 +488,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64 sum = 0;
|
||||
@@ -516,7 +516,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64 sum = 0;
|
||||
@@ -544,7 +544,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<float> InvokeAsync(IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<float> AverageAsync(IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single sum = 0;
|
||||
@@ -572,7 +572,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single sum = 0;
|
||||
@@ -600,7 +600,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single sum = 0;
|
||||
@@ -628,7 +628,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single sum = 0;
|
||||
@@ -656,7 +656,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync(IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync(IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double sum = 0;
|
||||
@@ -684,7 +684,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double sum = 0;
|
||||
@@ -712,7 +712,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double sum = 0;
|
||||
@@ -740,7 +740,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double sum = 0;
|
||||
@@ -768,7 +768,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal> InvokeAsync(IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal> AverageAsync(IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal sum = 0;
|
||||
@@ -796,7 +796,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal sum = 0;
|
||||
@@ -824,7 +824,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal sum = 0;
|
||||
@@ -852,7 +852,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal sum = 0;
|
||||
@@ -880,7 +880,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync(IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync(IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32? sum = 0;
|
||||
@@ -893,7 +893,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = e.Current;
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -912,7 +912,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32? sum = 0;
|
||||
@@ -925,7 +925,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -944,7 +944,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32? sum = 0;
|
||||
@@ -957,7 +957,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -976,7 +976,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int32? sum = 0;
|
||||
@@ -989,7 +989,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current, cancellationToken);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1008,7 +1008,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync(IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync(IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64? sum = 0;
|
||||
@@ -1021,7 +1021,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = e.Current;
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1040,7 +1040,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64? sum = 0;
|
||||
@@ -1053,7 +1053,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1072,7 +1072,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64? sum = 0;
|
||||
@@ -1085,7 +1085,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1104,7 +1104,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Int64? sum = 0;
|
||||
@@ -1117,7 +1117,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current, cancellationToken);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1136,7 +1136,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (double)sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<float?> InvokeAsync(IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<float?> AverageAsync(IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single? sum = 0;
|
||||
@@ -1149,7 +1149,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = e.Current;
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1168,7 +1168,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float?> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single? sum = 0;
|
||||
@@ -1181,7 +1181,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1200,7 +1200,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float?> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single? sum = 0;
|
||||
@@ -1213,7 +1213,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1232,7 +1232,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<float?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<float?> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Single? sum = 0;
|
||||
@@ -1245,7 +1245,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current, cancellationToken);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1264,7 +1264,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return (float)(sum / count);
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync(IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync(IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double? sum = 0;
|
||||
@@ -1277,7 +1277,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = e.Current;
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1296,7 +1296,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double? sum = 0;
|
||||
@@ -1309,7 +1309,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1328,7 +1328,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double? sum = 0;
|
||||
@@ -1341,7 +1341,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1360,7 +1360,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<double?> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Double? sum = 0;
|
||||
@@ -1373,7 +1373,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current, cancellationToken);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1392,7 +1392,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal?> InvokeAsync(IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal?> AverageAsync(IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal? sum = 0;
|
||||
@@ -1405,7 +1405,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = e.Current;
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1424,7 +1424,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal?> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal? sum = 0;
|
||||
@@ -1437,7 +1437,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1456,7 +1456,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal?> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal? sum = 0;
|
||||
@@ -1469,7 +1469,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
@@ -1488,7 +1488,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum / count;
|
||||
}
|
||||
|
||||
public static async UniTask<decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<decimal?> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
Decimal? sum = 0;
|
||||
@@ -1501,7 +1501,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
var v = await selector(e.Current, cancellationToken);
|
||||
if (v.HasValue)
|
||||
{
|
||||
checked
|
||||
checked
|
||||
{
|
||||
sum += v.Value;
|
||||
count++;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Average.InvokeAsync(source, cancellationToken);
|
||||
return Average.AverageAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= ret #>> AverageAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -47,7 +47,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= ret #>> AverageAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -55,15 +55,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= ret #>> AverageAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<<#= ret #>> AverageAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Average.InvokeAsync(source, selector, cancellationToken);
|
||||
return Average.AverageAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
<# } #>
|
||||
@@ -72,7 +72,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
internal static class Average
|
||||
{
|
||||
<# foreach(var (t, ret) in types) { #>
|
||||
public static async UniTask<<#= ret #>> InvokeAsync(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= ret #>> AverageAsync(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
<#= TypeName(t) #> sum = 0;
|
||||
@@ -112,7 +112,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return <#= CalcResult(t) #>;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= ret #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= ret #>> AverageAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
<#= TypeName(t) #> sum = 0;
|
||||
@@ -152,7 +152,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return <#= CalcResult(t) #>;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= ret #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= ret #>> AverageAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
<#= TypeName(t) #> sum = 0;
|
||||
@@ -192,7 +192,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return <#= CalcResult(t) #>;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= ret #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= ret #>> AverageAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
<#= TypeName(t) #> sum = 0;
|
||||
|
||||
@@ -38,10 +38,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<IList<TSource>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, cancellationToken);
|
||||
return new _Buffer(source, count, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<IList<TSource>>
|
||||
sealed class _Buffer : MoveNextSource, IUniTaskAsyncEnumerator<IList<TSource>>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -56,11 +56,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
bool completed;
|
||||
List<TSource> buffer;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
public _Buffer(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.count = count;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public IList<TSource> Current { get; private set; }
|
||||
@@ -128,7 +130,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Buffer)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -167,6 +169,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
@@ -191,10 +194,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<IList<TSource>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, skip, cancellationToken);
|
||||
return new _BufferSkip(source, count, skip, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<IList<TSource>>
|
||||
sealed class _BufferSkip : MoveNextSource, IUniTaskAsyncEnumerator<IList<TSource>>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -211,12 +214,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Queue<List<TSource>> buffers;
|
||||
int index = 0;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, int skip, CancellationToken cancellationToken)
|
||||
public _BufferSkip(IUniTaskAsyncEnumerable<TSource> source, int count, int skip, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.count = count;
|
||||
this.skip = skip;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public IList<TSource> Current { get; private set; }
|
||||
@@ -282,7 +286,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_BufferSkip)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -329,6 +333,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _Cast(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<object, TResult>
|
||||
class _Cast : AsyncEnumeratorBase<object, TResult>
|
||||
{
|
||||
public Enumerator(IUniTaskAsyncEnumerable<object> source, CancellationToken cancellationToken)
|
||||
public _Cast(IUniTaskAsyncEnumerable<object> source, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
|
||||
11372
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/CombineLatest.cs
Normal file
11372
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/CombineLatest.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb07f6e88287e34d9b9301a572284a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
221
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/CombineLatest.tt
Normal file
221
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/CombineLatest.tt
Normal file
@@ -0,0 +1,221 @@
|
||||
<#@ template debug="false" hostspecific="false" language="C#" #>
|
||||
<#@ assembly name="System.Core" #>
|
||||
<#@ import namespace="System.Linq" #>
|
||||
<#@ import namespace="System.Text" #>
|
||||
<#@ import namespace="System.Collections.Generic" #>
|
||||
<#@ output extension=".cs" #>
|
||||
<#
|
||||
var tMax = 15;
|
||||
Func<int, string> typeArgs = x => string.Join(", ", Enumerable.Range(1, x).Select(x => $"T{x}")) + ", TResult";
|
||||
Func<int, string> paramArgs = x => string.Join(", ", Enumerable.Range(1, x).Select(x => $"IUniTaskAsyncEnumerable<T{x}> source{x}"));
|
||||
Func<int, string> parameters = x => string.Join(", ", Enumerable.Range(1, x).Select(x => $"source{x}"));
|
||||
|
||||
|
||||
#>
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
<# for(var i = 2; i <= tMax; i++) { #>
|
||||
public static IUniTaskAsyncEnumerable<TResult> CombineLatest<<#= typeArgs(i) #>>(this <#= paramArgs(i) #>, Func<<#= typeArgs(i) #>> resultSelector)
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
Error.ThrowArgumentNullException(source<#= j #>, nameof(source<#= j #>));
|
||||
<# } #>
|
||||
Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
|
||||
|
||||
return new CombineLatest<<#= typeArgs(i) #>>(<#= parameters(i) #>, resultSelector);
|
||||
}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
|
||||
<# for(var i = 2; i <= tMax; i++) { #>
|
||||
internal class CombineLatest<<#= typeArgs(i) #>> : IUniTaskAsyncEnumerable<TResult>
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
readonly IUniTaskAsyncEnumerable<T<#= j #>> source<#= j #>;
|
||||
<# } #>
|
||||
readonly Func<<#= typeArgs(i) #>> resultSelector;
|
||||
|
||||
public CombineLatest(<#= paramArgs(i) #>, Func<<#= typeArgs(i) #>> resultSelector)
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
this.source<#= j #> = source<#= j #>;
|
||||
<# } #>
|
||||
this.resultSelector = resultSelector;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _CombineLatest(<#= parameters(i) #>, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
class _CombineLatest : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
static readonly Action<object> Completed<#= j #>Delegate = Completed<#= j #>;
|
||||
<# } #>
|
||||
const int CompleteCount = <#= i #>;
|
||||
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
readonly IUniTaskAsyncEnumerable<T<#= j #>> source<#= j #>;
|
||||
<# } #>
|
||||
readonly Func<<#= typeArgs(i) #>> resultSelector;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
IUniTaskAsyncEnumerator<T<#= j #>> enumerator<#= j #>;
|
||||
UniTask<bool>.Awaiter awaiter<#= j #>;
|
||||
bool hasCurrent<#= j #>;
|
||||
bool running<#= j #>;
|
||||
T<#= j #> current<#= j #>;
|
||||
|
||||
<# } #>
|
||||
int completedCount;
|
||||
bool syncRunning;
|
||||
TResult result;
|
||||
|
||||
public _CombineLatest(<#= paramArgs(i) #>, Func<<#= typeArgs(i) #>> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
this.source<#= j #> = source<#= j #>;
|
||||
<# } #>
|
||||
this.resultSelector = resultSelector;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current => result;
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
if (completedCount == CompleteCount) return CompletedTasks.False;
|
||||
|
||||
if (enumerator1 == null)
|
||||
{
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
enumerator<#= j #> = source<#= j #>.GetAsyncEnumerator(cancellationToken);
|
||||
<# } #>
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
|
||||
AGAIN:
|
||||
syncRunning = true;
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
if (!running<#= j #>)
|
||||
{
|
||||
running<#= j #> = true;
|
||||
awaiter<#= j #> = enumerator<#= j #>.MoveNextAsync().GetAwaiter();
|
||||
if (awaiter<#= j #>.IsCompleted)
|
||||
{
|
||||
Completed<#= j #>(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
awaiter<#= j #>.SourceOnCompleted(Completed<#= j #>Delegate, this);
|
||||
}
|
||||
}
|
||||
<# } #>
|
||||
|
||||
if (<#= string.Join(" || ", Enumerable.Range(1, i).Select(x => $"!running{x}")) #>)
|
||||
{
|
||||
goto AGAIN;
|
||||
}
|
||||
syncRunning = false;
|
||||
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
static void Completed<#= j #>(object state)
|
||||
{
|
||||
var self = (_CombineLatest)state;
|
||||
self.running<#= j #> = false;
|
||||
|
||||
try
|
||||
{
|
||||
if (self.awaiter<#= j #>.GetResult())
|
||||
{
|
||||
self.hasCurrent<#= j #> = true;
|
||||
self.current<#= j #> = self.enumerator<#= j #>.Current;
|
||||
goto SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
self.running<#= j #> = true; // as complete, no more call MoveNextAsync.
|
||||
if (Interlocked.Increment(ref self.completedCount) == CompleteCount)
|
||||
{
|
||||
goto COMPLETE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
self.running<#= j #> = true; // as complete, no more call MoveNextAsync.
|
||||
self.completedCount = CompleteCount;
|
||||
self.completionSource.TrySetException(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
SUCCESS:
|
||||
if (!self.TrySetResult())
|
||||
{
|
||||
if (self.syncRunning) return;
|
||||
self.running<#= j #> = true; // as complete, no more call MoveNextAsync.
|
||||
try
|
||||
{
|
||||
self.awaiter<#= j #> = self.enumerator<#= j #>.MoveNextAsync().GetAwaiter();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
self.completedCount = CompleteCount;
|
||||
self.completionSource.TrySetException(ex);
|
||||
return;
|
||||
}
|
||||
|
||||
self.awaiter<#= j #>.SourceOnCompleted(Completed<#= j #>Delegate, self);
|
||||
}
|
||||
return;
|
||||
COMPLETE:
|
||||
self.completionSource.TrySetResult(false);
|
||||
return;
|
||||
}
|
||||
|
||||
<# } #>
|
||||
bool TrySetResult()
|
||||
{
|
||||
if (<#= string.Join(" && ", Enumerable.Range(1, i).Select(x => $"hasCurrent{x}")) #>)
|
||||
{
|
||||
result = resultSelector(<#= string.Join(", ", Enumerable.Range(1, i).Select(x => $"current{x}")) #>);
|
||||
completionSource.TrySetResult(true);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
<# for(var j = 1; j <= i; j++) { #>
|
||||
if (enumerator<#= j #> != null)
|
||||
{
|
||||
await enumerator<#= j #>.DisposeAsync();
|
||||
}
|
||||
<# } #>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<# } #>
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1b8cfa9d17af814a971ee2224aaaaa2
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -28,10 +28,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(first, second, cancellationToken);
|
||||
return new _Concat(first, second, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _Concat : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -51,12 +51,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, CancellationToken cancellationToken)
|
||||
public _Concat(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, CancellationToken cancellationToken)
|
||||
{
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.cancellationToken = cancellationToken;
|
||||
this.iteratingState = IteratingState.IteratingFirst;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -108,7 +109,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Concat)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -150,6 +151,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -17,13 +17,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return Contains.InvokeAsync(source, value, comparer, cancellationToken);
|
||||
return Contains.ContainsAsync(source, value, comparer, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Contains
|
||||
{
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> ContainsAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Count.InvokeAsync(source, cancellationToken);
|
||||
return Count.CountAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> CountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Count.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Count.CountAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> CountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Count.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Count.CountAwaitAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> CountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,13 +34,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Count.InvokeAsync(source, predicate, cancellationToken);
|
||||
return Count.CountAwaitWithCancellationAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Count
|
||||
{
|
||||
internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
internal static async UniTask<int> CountAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<int> CountAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<int> CountAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<int> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<int> CountAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
var count = 0;
|
||||
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, defaultValue, cancellationToken);
|
||||
return new _DefaultIfEmpty(source, defaultValue, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _DefaultIfEmpty : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
enum IteratingState : byte
|
||||
{
|
||||
@@ -56,13 +56,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, TSource defaultValue, CancellationToken cancellationToken)
|
||||
public _DefaultIfEmpty(IUniTaskAsyncEnumerable<TSource> source, TSource defaultValue, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.defaultValue = defaultValue;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
this.iteratingState = IteratingState.Empty;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -99,7 +100,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_DefaultIfEmpty)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -128,6 +129,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return new DistinctAwaitCancellation<TSource, TKey>(source, keySelector, comparer);
|
||||
return new DistinctAwaitWithCancellation<TSource, TKey>(source, keySelector, comparer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,14 +76,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, comparer, cancellationToken);
|
||||
return new _Distinct(source, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _Distinct : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly HashSet<TSource> set;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
public _Distinct(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -129,15 +129,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _Distinct(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _Distinct : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly HashSet<TKey> set;
|
||||
readonly Func<TSource, TKey> keySelector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _Distinct(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -184,15 +184,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _DistinctAwait(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
class _DistinctAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
{
|
||||
readonly HashSet<TKey> set;
|
||||
readonly Func<TSource, UniTask<TKey>> keySelector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -222,13 +222,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DistinctAwaitCancellation<TSource, TKey> : IUniTaskAsyncEnumerable<TSource>
|
||||
internal sealed class DistinctAwaitWithCancellation<TSource, TKey> : IUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TKey>> keySelector;
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
|
||||
public DistinctAwaitCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
|
||||
public DistinctAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
@@ -237,15 +237,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _DistinctAwaitWithCancellation(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
class _DistinctAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
{
|
||||
readonly HashSet<TKey> set;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TKey>> keySelector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return new DistinctUntilChangedAwaitCancellation<TSource, TKey>(source, keySelector, comparer);
|
||||
return new DistinctUntilChangedAwaitWithCancellation<TSource, TKey>(source, keySelector, comparer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,16 +76,16 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, comparer, cancellationToken);
|
||||
return new _DistinctUntilChanged(source, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _DistinctUntilChanged : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly IEqualityComparer<TSource> comparer;
|
||||
TSource prev;
|
||||
bool first;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctUntilChanged(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -133,17 +133,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _DistinctUntilChanged(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _DistinctUntilChanged : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
readonly Func<TSource, TKey> keySelector;
|
||||
TKey prev;
|
||||
bool first;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctUntilChanged(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -194,17 +194,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _DistinctUntilChangedAwait(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
class _DistinctUntilChangedAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
{
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
readonly Func<TSource, UniTask<TKey>> keySelector;
|
||||
TKey prev;
|
||||
bool first;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctUntilChangedAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -237,13 +237,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class DistinctUntilChangedAwaitCancellation<TSource, TKey> : IUniTaskAsyncEnumerable<TSource>
|
||||
internal sealed class DistinctUntilChangedAwaitWithCancellation<TSource, TKey> : IUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TKey>> keySelector;
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
|
||||
public DistinctUntilChangedAwaitCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
|
||||
public DistinctUntilChangedAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
@@ -252,17 +252,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, comparer, cancellationToken);
|
||||
return new _DistinctUntilChangedAwaitWithCancellation(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
class _DistinctUntilChangedAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, TKey>
|
||||
{
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TKey>> keySelector;
|
||||
TKey prev;
|
||||
bool first;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _DistinctUntilChangedAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
|
||||
@@ -101,10 +101,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, onNext, onError, onCompleted, cancellationToken);
|
||||
return new _Do(source, onNext, onError, onCompleted, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _Do : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -117,13 +117,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted, CancellationToken cancellationToken)
|
||||
public _Do(IUniTaskAsyncEnumerable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.onNext = onNext;
|
||||
this.onError = onError;
|
||||
this.onCompleted = onCompleted;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -199,7 +200,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Do)state;
|
||||
|
||||
if (self.TryGetResultWithNotification(self.awaiter, out var result))
|
||||
{
|
||||
@@ -244,6 +245,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -10,20 +10,20 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return ElementAt.InvokeAsync(source, index, cancellationToken, false);
|
||||
return ElementAt.ElementAtAsync(source, index, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> ElementAtOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, int index, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return ElementAt.InvokeAsync(source, index, cancellationToken, true);
|
||||
return ElementAt.ElementAtAsync(source, index, cancellationToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ElementAt
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, int index, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> ElementAtAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, int index, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return Enumerator.Instance;
|
||||
return _Empty.Instance;
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<T>
|
||||
class _Empty : IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
public static readonly IUniTaskAsyncEnumerator<T> Instance = new Enumerator();
|
||||
public static readonly IUniTaskAsyncEnumerator<T> Instance = new _Empty();
|
||||
|
||||
Enumerator()
|
||||
_Empty()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(first, second, comparer, cancellationToken);
|
||||
return new _Except(first, second, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _Except : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
static Action<object> HashSetAsyncCoreDelegate = HashSetAsyncCore;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
HashSet<TSource> set;
|
||||
UniTask<HashSet<TSource>>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
public _Except(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(first, cancellationToken)
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void HashSetAsyncCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Except)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return First.InvokeAsync(source, cancellationToken, false);
|
||||
return First.FirstAsync(source, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return First.FirstAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return First.FirstAwaitAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,14 +34,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return First.FirstAwaitWithCancellationAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return First.InvokeAsync(source, cancellationToken, true);
|
||||
return First.FirstAsync(source, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return First.FirstAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstOrDefaultAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return First.FirstAwaitAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> FirstOrDefaultAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -65,13 +65,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return First.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return First.FirstAwaitWithCancellationAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class First
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> FirstAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -101,7 +101,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> FirstAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -133,7 +133,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> FirstAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -165,7 +165,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> FirstAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAsync(source, action, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask ForEachAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Action<TSource, Int32> action, CancellationToken cancellationToken = default)
|
||||
@@ -19,7 +19,23 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAsync(source, action, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>Obsolete(Error), Use Use ForEachAwaitAsync instead.</summary>
|
||||
[Obsolete("Use ForEachAwaitAsync instead.", true)]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static UniTask ForEachAsync<T>(this IUniTaskAsyncEnumerable<T> source, Func<T, UniTask> action, CancellationToken cancellationToken = default)
|
||||
{
|
||||
throw new NotSupportedException("Use ForEachAwaitAsync instead.");
|
||||
}
|
||||
|
||||
/// <summary>Obsolete(Error), Use Use ForEachAwaitAsync instead.</summary>
|
||||
[Obsolete("Use ForEachAwaitAsync instead.", true)]
|
||||
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
|
||||
public static UniTask ForEachAsync<T>(this IUniTaskAsyncEnumerable<T> source, Func<T, int, UniTask> action, CancellationToken cancellationToken = default)
|
||||
{
|
||||
throw new NotSupportedException("Use ForEachAwaitAsync instead.");
|
||||
}
|
||||
|
||||
public static UniTask ForEachAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask> action, CancellationToken cancellationToken = default)
|
||||
@@ -27,7 +43,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAwaitAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAwaitAsync(source, action, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask ForEachAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, UniTask> action, CancellationToken cancellationToken = default)
|
||||
@@ -35,7 +51,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAwaitAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAwaitAsync(source, action, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask ForEachAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask> action, CancellationToken cancellationToken = default)
|
||||
@@ -43,7 +59,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAwaitWithCancellationAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAwaitWithCancellationAsync(source, action, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask ForEachAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, CancellationToken, UniTask> action, CancellationToken cancellationToken = default)
|
||||
@@ -51,13 +67,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(action, nameof(action));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.InvokeAwaitWithCancellationAsync(source, action, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ForEach.ForEachAwaitWithCancellationAsync(source, action, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ForEach
|
||||
{
|
||||
public static async UniTask InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Action<TSource> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Action<TSource> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -76,7 +92,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Action<TSource, Int32> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Action<TSource, Int32> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -96,7 +112,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask InvokeAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -115,7 +131,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask InvokeAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, UniTask> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, UniTask> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -135,7 +151,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask InvokeAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -154,7 +170,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask InvokeAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, CancellationToken, UniTask> action, CancellationToken cancellationToken)
|
||||
public static async UniTask ForEachAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, CancellationToken, UniTask> action, CancellationToken cancellationToken)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -235,10 +235,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return new _GroupBy(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
sealed class _GroupBy : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, TKey> keySelector;
|
||||
@@ -248,13 +248,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupBy(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
this.elementSelector = elementSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public IGrouping<TKey, TElement> Current { get; private set; }
|
||||
@@ -313,6 +314,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
@@ -342,10 +344,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupBy(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupBy : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, TKey> keySelector;
|
||||
@@ -356,7 +358,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupBy(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<TKey, IEnumerable<TElement>, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
@@ -364,6 +366,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -423,6 +426,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
@@ -450,10 +454,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return new _GroupByAwait(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
sealed class _GroupByAwait : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, UniTask<TKey>> keySelector;
|
||||
@@ -463,13 +467,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupByAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
this.elementSelector = elementSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public IGrouping<TKey, TElement> Current { get; private set; }
|
||||
@@ -528,6 +533,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
@@ -557,10 +563,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupByAwait(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupByAwait : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
|
||||
|
||||
@@ -574,7 +580,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
UniTask<TResult>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, Func<TKey, IEnumerable<TElement>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupByAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, Func<TKey, IEnumerable<TElement>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
@@ -582,6 +588,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -650,7 +657,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupByAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -661,6 +668,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
@@ -688,10 +696,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return new _GroupByAwaitWithCancellation(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
sealed class _GroupByAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<IGrouping<TKey, TElement>>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TKey>> keySelector;
|
||||
@@ -701,13 +709,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupByAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
this.elementSelector = elementSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public IGrouping<TKey, TElement> Current { get; private set; }
|
||||
@@ -766,6 +775,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
@@ -795,10 +805,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupByAwaitWithCancellation(source, keySelector, elementSelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupByAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
|
||||
|
||||
@@ -812,7 +822,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IEnumerator<IGrouping<TKey, TElement>> groupEnumerator;
|
||||
UniTask<TResult>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, Func<TKey, IEnumerable<TElement>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupByAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, Func<TKey, IEnumerable<TElement>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.keySelector = keySelector;
|
||||
@@ -820,6 +830,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -888,7 +899,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupByAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -899,6 +910,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (groupEnumerator != null)
|
||||
{
|
||||
groupEnumerator.Dispose();
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(innerKeySelector, nameof(innerKeySelector));
|
||||
Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
|
||||
|
||||
return new GroupJoinWithCancellationAwait<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
|
||||
return new GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, EqualityComparer<TKey>.Default);
|
||||
}
|
||||
|
||||
public static IUniTaskAsyncEnumerable<TResult> GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(this IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
|
||||
@@ -74,7 +74,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(resultSelector, nameof(resultSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return new GroupJoinWithCancellationAwait<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
|
||||
return new GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult>(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,10 +100,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupJoin(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupJoin : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -120,7 +120,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupJoin(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, IEnumerable<TInner>, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -129,6 +129,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -186,7 +187,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoin)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -208,6 +209,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
@@ -239,10 +241,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupJoinAwait(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupJoinAwait : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
|
||||
@@ -264,7 +266,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<TResult>.Awaiter resultAwaiter;
|
||||
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupJoinAwait(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -273,6 +275,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -330,7 +333,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -364,7 +367,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void OuterKeySelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.outerKeyAwaiter, out var result))
|
||||
{
|
||||
@@ -390,7 +393,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.resultAwaiter, out var result))
|
||||
{
|
||||
@@ -401,6 +404,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
@@ -411,7 +415,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class GroupJoinWithCancellationAwait<TOuter, TInner, TKey, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
internal sealed class GroupJoinAwaitWithCancellation<TOuter, TInner, TKey, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TOuter> outer;
|
||||
readonly IUniTaskAsyncEnumerable<TInner> inner;
|
||||
@@ -420,7 +424,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
readonly Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector;
|
||||
readonly IEqualityComparer<TKey> comparer;
|
||||
|
||||
public GroupJoinWithCancellationAwait(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
|
||||
public GroupJoinAwaitWithCancellation(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -432,10 +436,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _GroupJoinAwaitWithCancellation(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _GroupJoinAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
readonly static Action<object> ResultSelectCoreDelegate = ResultSelectCore;
|
||||
@@ -457,7 +461,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<TResult>.Awaiter resultAwaiter;
|
||||
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _GroupJoinAwaitWithCancellation(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, IEnumerable<TInner>, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -466,6 +470,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -523,7 +528,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -557,7 +562,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void OuterKeySelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.outerKeyAwaiter, out var result))
|
||||
{
|
||||
@@ -583,7 +588,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_GroupJoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.resultAwaiter, out var result))
|
||||
{
|
||||
@@ -594,6 +599,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(first, second, comparer, cancellationToken);
|
||||
return new _Intersect(first, second, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _Intersect : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
static Action<object> HashSetAsyncCoreDelegate = HashSetAsyncCore;
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
HashSet<TSource> set;
|
||||
UniTask<HashSet<TSource>>.Awaiter awaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
public _Intersect(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
|
||||
: base(first, cancellationToken)
|
||||
{
|
||||
@@ -81,7 +81,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void HashSetAsyncCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Intersect)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
|
||||
@@ -99,10 +99,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _Join(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _Join : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -122,7 +122,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
bool continueNext;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _Join(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, TKey> outerKeySelector, Func<TInner, TKey> innerKeySelector, Func<TOuter, TInner, TResult> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -131,6 +131,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -215,7 +216,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_Join)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -248,6 +249,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (valueEnumerator != null)
|
||||
{
|
||||
valueEnumerator.Dispose();
|
||||
@@ -284,10 +286,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _JoinAwait(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _JoinAwait : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
static readonly Action<object> OuterSelectCoreDelegate = OuterSelectCore;
|
||||
@@ -312,7 +314,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
bool continueNext;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, TInner, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _JoinAwait(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, UniTask<TKey>> outerKeySelector, Func<TInner, UniTask<TKey>> innerKeySelector, Func<TOuter, TInner, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -321,6 +323,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -408,7 +411,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -442,7 +445,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void OuterSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.outerKeyAwaiter, out var key))
|
||||
{
|
||||
@@ -465,7 +468,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.resultAwaiter, out var result))
|
||||
{
|
||||
@@ -476,6 +479,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (valueEnumerator != null)
|
||||
{
|
||||
valueEnumerator.Dispose();
|
||||
@@ -512,10 +516,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
return new _JoinAwaitWithCancellation(outer, inner, outerKeySelector, innerKeySelector, resultSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _JoinAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
static readonly Action<object> OuterSelectCoreDelegate = OuterSelectCore;
|
||||
@@ -540,7 +544,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
bool continueNext;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
public _JoinAwaitWithCancellation(IUniTaskAsyncEnumerable<TOuter> outer, IUniTaskAsyncEnumerable<TInner> inner, Func<TOuter, CancellationToken, UniTask<TKey>> outerKeySelector, Func<TInner, CancellationToken, UniTask<TKey>> innerKeySelector, Func<TOuter, TInner, CancellationToken, UniTask<TResult>> resultSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
this.outer = outer;
|
||||
this.inner = inner;
|
||||
@@ -549,6 +553,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
this.resultSelector = resultSelector;
|
||||
this.comparer = comparer;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -636,7 +641,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -670,7 +675,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void OuterSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.outerKeyAwaiter, out var key))
|
||||
{
|
||||
@@ -693,7 +698,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_JoinAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.resultAwaiter, out var result))
|
||||
{
|
||||
@@ -704,6 +709,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (valueEnumerator != null)
|
||||
{
|
||||
valueEnumerator.Dispose();
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Last.InvokeAsync(source, cancellationToken, false);
|
||||
return Last.LastAsync(source, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return Last.LastAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return Last.LastAwaitAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,14 +34,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return Last.LastAwaitWithCancellationAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Last.InvokeAsync(source, cancellationToken, true);
|
||||
return Last.LastAsync(source, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return Last.LastAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastOrDefaultAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return Last.LastAwaitAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> LastOrDefaultAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -65,13 +65,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return Last.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return Last.LastAwaitWithCancellationAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class Last
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> LastAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -108,7 +108,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> LastAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -151,7 +151,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> LastAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -194,7 +194,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> LastAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return LongCount.InvokeAsync(source, cancellationToken);
|
||||
return LongCount.LongCountAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<long> LongCountAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return LongCount.InvokeAsync(source, predicate, cancellationToken);
|
||||
return LongCount.LongCountAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<long> LongCountAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return LongCount.InvokeAsync(source, predicate, cancellationToken);
|
||||
return LongCount.LongCountAwaitAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<long> LongCountAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,13 +34,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return LongCount.InvokeAsync(source, predicate, cancellationToken);
|
||||
return LongCount.LongCountAwaitWithCancellationAsync(source, predicate, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class LongCount
|
||||
{
|
||||
internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
internal static async UniTask<long> LongCountAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<long> LongCountAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
@@ -89,7 +89,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<long> LongCountAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
@@ -115,7 +115,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return count;
|
||||
}
|
||||
|
||||
internal static async UniTask<long> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
internal static async UniTask<long> LongCountAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken)
|
||||
{
|
||||
long count = 0;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Max.InvokeAsync(source, cancellationToken);
|
||||
return Max.MaxAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MaxAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken = default)
|
||||
@@ -19,7 +19,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Max.InvokeAsync(source, selector, cancellationToken);
|
||||
return Max.MaxAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MaxAwaitAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -27,21 +27,21 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Max.InvokeAsync(source, selector, cancellationToken);
|
||||
return Max.MaxAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MaxAwaitCancellationAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<TResult> MaxAwaitWithCancellationAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Max.InvokeAsync(source, selector, cancellationToken);
|
||||
return Max.MaxAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static partial class Max
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<TSource> MaxAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
TSource value = default;
|
||||
var comparer = Comparer<TSource>.Default;
|
||||
@@ -80,7 +80,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MaxAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
@@ -119,7 +119,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MaxAwaitAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
@@ -158,7 +158,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MaxAwaitWithCancellationAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Min.InvokeAsync(source, cancellationToken);
|
||||
return Min.MinAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MinAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken = default)
|
||||
@@ -19,7 +19,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Min.InvokeAsync(source, selector, cancellationToken);
|
||||
return Min.MinAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MinAwaitAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -27,21 +27,21 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Min.InvokeAsync(source, selector, cancellationToken);
|
||||
return Min.MinAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<TResult> MinAwaitCancellationAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<TResult> MinAwaitWithCancellationAsync<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Min.InvokeAsync(source, selector, cancellationToken);
|
||||
return Min.MinAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static partial class Min
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<TSource> MinAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
TSource value = default;
|
||||
var comparer = Comparer<TSource>.Default;
|
||||
@@ -80,7 +80,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MinAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
@@ -119,7 +119,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MinAwaitAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
@@ -158,7 +158,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<TResult> InvokeAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<TResult> MinAwaitWithCancellationAsync<TSource, TResult>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
TResult value = default;
|
||||
var comparer = Comparer<TResult>.Default;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -38,7 +38,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return <#= minMax #>.InvokeAsync(source, cancellationToken);
|
||||
return <#= minMax #>.<#= minMax #>Async(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> <#= minMax #>Async<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -46,7 +46,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return <#= minMax #>.InvokeAsync(source, selector, cancellationToken);
|
||||
return <#= minMax #>.<#= minMax #>Async(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> <#= minMax #>AwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -54,15 +54,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return <#= minMax #>.InvokeAsync(source, selector, cancellationToken);
|
||||
return <#= minMax #>.<#= minMax #>AwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> <#= minMax #>AwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<<#= TypeName(t) #>> <#= minMax #>AwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return <#= minMax #>.InvokeAsync(source, selector, cancellationToken);
|
||||
return <#= minMax #>.<#= minMax #>AwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
<# } #>
|
||||
@@ -71,7 +71,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
internal static partial class <#= minMax #>
|
||||
{
|
||||
<# foreach(var t in types) { #>
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> <#= minMax #>Async(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> value = default;
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> <#= minMax #>Async<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> value = default;
|
||||
|
||||
@@ -163,7 +163,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> <#= minMax #>AwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> value = default;
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return value;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> <#= minMax #>AwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> value = default;
|
||||
|
||||
|
||||
@@ -20,14 +20,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(cancellationToken);
|
||||
return new _Never(cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<T>
|
||||
class _Never : IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public Enumerator(CancellationToken cancellationToken)
|
||||
public _Never(CancellationToken cancellationToken)
|
||||
{
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,12 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _OfType(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<object, TResult>
|
||||
class _OfType : AsyncEnumeratorBase<object, TResult>
|
||||
{
|
||||
public Enumerator(IUniTaskAsyncEnumerable<object> source, CancellationToken cancellationToken)
|
||||
public _OfType(IUniTaskAsyncEnumerable<object> source, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
|
||||
@@ -407,10 +407,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TElement> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(this, cancellationToken);
|
||||
return new _OrderedAsyncEnumerator(this, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TElement>
|
||||
class _OrderedAsyncEnumerator : MoveNextSource, IUniTaskAsyncEnumerator<TElement>
|
||||
{
|
||||
protected readonly OrderedAsyncEnumerable<TElement> parent;
|
||||
CancellationToken cancellationToken;
|
||||
@@ -418,10 +418,11 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
int[] map;
|
||||
int index;
|
||||
|
||||
public Enumerator(OrderedAsyncEnumerable<TElement> parent, CancellationToken cancellationToken)
|
||||
public _OrderedAsyncEnumerator(OrderedAsyncEnumerable<TElement> parent, CancellationToken cancellationToken)
|
||||
{
|
||||
this.parent = parent;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TElement Current { get; private set; }
|
||||
@@ -477,6 +478,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
128
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Pairwise.cs
Normal file
128
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Pairwise.cs
Normal file
@@ -0,0 +1,128 @@
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IUniTaskAsyncEnumerable<(TSource, TSource)> Pairwise<TSource>(this IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return new Pairwise<TSource>(source);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class Pairwise<TSource> : IUniTaskAsyncEnumerable<(TSource, TSource)>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
|
||||
public Pairwise(IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<(TSource, TSource)> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _Pairwise(source, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class _Pairwise : MoveNextSource, IUniTaskAsyncEnumerator<(TSource, TSource)>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
TSource prev;
|
||||
bool isFirst;
|
||||
|
||||
public _Pairwise(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public (TSource, TSource) Current { get; private set; }
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (enumerator == null)
|
||||
{
|
||||
isFirst = true;
|
||||
enumerator = source.GetAsyncEnumerator(cancellationToken);
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
SourceMoveNext();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
void SourceMoveNext()
|
||||
{
|
||||
try
|
||||
{
|
||||
awaiter = enumerator.MoveNextAsync().GetAwaiter();
|
||||
if (awaiter.IsCompleted)
|
||||
{
|
||||
MoveNextCore(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (_Pairwise)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
if (self.isFirst)
|
||||
{
|
||||
self.isFirst = false;
|
||||
self.prev = self.enumerator.Current;
|
||||
self.SourceMoveNext(); // run again. okay to use recursive(only one more).
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = self.prev;
|
||||
self.prev = self.enumerator.Current;
|
||||
self.Current = (p, self.prev);
|
||||
self.completionSource.TrySetResult(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cddbf051d2a88f549986c468b23214af
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
171
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Publish.cs
Normal file
171
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Publish.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IConnectableUniTaskAsyncEnumerable<TSource> Publish<TSource>(this IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return new Publish<TSource>(source);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class Publish<TSource> : IConnectableUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly CancellationTokenSource cancellationTokenSource;
|
||||
|
||||
TriggerEvent<TSource> trigger;
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
IDisposable connectedDisposable;
|
||||
bool isCompleted;
|
||||
|
||||
public Publish(IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationTokenSource = new CancellationTokenSource();
|
||||
}
|
||||
|
||||
public IDisposable Connect()
|
||||
{
|
||||
if (connectedDisposable != null) return connectedDisposable;
|
||||
|
||||
if (enumerator == null)
|
||||
{
|
||||
enumerator = source.GetAsyncEnumerator(cancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
ConsumeEnumerator().Forget();
|
||||
|
||||
connectedDisposable = new ConnectDisposable(cancellationTokenSource);
|
||||
return connectedDisposable;
|
||||
}
|
||||
|
||||
async UniTaskVoid ConsumeEnumerator()
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await enumerator.MoveNextAsync())
|
||||
{
|
||||
trigger.SetResult(enumerator.Current);
|
||||
}
|
||||
trigger.SetCompleted();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
trigger.SetError(ex);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
isCompleted = true;
|
||||
await enumerator.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _Publish(this, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class ConnectDisposable : IDisposable
|
||||
{
|
||||
readonly CancellationTokenSource cancellationTokenSource;
|
||||
|
||||
public ConnectDisposable(CancellationTokenSource cancellationTokenSource)
|
||||
{
|
||||
this.cancellationTokenSource = cancellationTokenSource;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.cancellationTokenSource.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
sealed class _Publish : MoveNextSource, IUniTaskAsyncEnumerator<TSource>, ITriggerHandler<TSource>
|
||||
{
|
||||
static readonly Action<object> CancelDelegate = OnCanceled;
|
||||
|
||||
readonly Publish<TSource> parent;
|
||||
CancellationToken cancellationToken;
|
||||
CancellationTokenRegistration cancellationTokenRegistration;
|
||||
bool isDisposed;
|
||||
|
||||
public _Publish(Publish<TSource> parent, CancellationToken cancellationToken)
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested) return;
|
||||
|
||||
this.parent = parent;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
if (cancellationToken.CanBeCanceled)
|
||||
{
|
||||
this.cancellationTokenRegistration = cancellationToken.RegisterWithoutCaptureExecutionContext(CancelDelegate, this);
|
||||
}
|
||||
|
||||
parent.trigger.Add(this);
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (parent.isCompleted) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
static void OnCanceled(object state)
|
||||
{
|
||||
var self = (_Publish)state;
|
||||
self.completionSource.TrySetCanceled(self.cancellationToken);
|
||||
self.DisposeAsync().Forget();
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
if (!isDisposed)
|
||||
{
|
||||
isDisposed = true;
|
||||
TaskTracker.RemoveTracking(this);
|
||||
cancellationTokenRegistration.Dispose();
|
||||
parent.trigger.Remove(this);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
|
||||
public void OnNext(TSource value)
|
||||
{
|
||||
Current = value;
|
||||
completionSource.TrySetResult(true);
|
||||
}
|
||||
|
||||
public void OnCanceled(CancellationToken cancellationToken)
|
||||
{
|
||||
completionSource.TrySetCanceled(cancellationToken);
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
completionSource.TrySetResult(false);
|
||||
}
|
||||
|
||||
public void OnError(Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 93c684d1e88c09d4e89b79437d97b810
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
103
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Queue.cs
Normal file
103
src/UniTask/Assets/Plugins/UniTask/Runtime/Linq/Queue.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IUniTaskAsyncEnumerable<TSource> Queue<TSource>(this IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
return new QueueOperator<TSource>(source);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class QueueOperator<TSource> : IUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
|
||||
public QueueOperator(IUniTaskAsyncEnumerable<TSource> source)
|
||||
{
|
||||
this.source = source;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _Queue(source, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class _Queue : IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
Channel<TSource> channel;
|
||||
IUniTaskAsyncEnumerator<TSource> channelEnumerator;
|
||||
IUniTaskAsyncEnumerator<TSource> sourceEnumerator;
|
||||
bool channelClosed;
|
||||
|
||||
public _Queue(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public TSource Current => channelEnumerator.Current;
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (sourceEnumerator == null)
|
||||
{
|
||||
sourceEnumerator = source.GetAsyncEnumerator(cancellationToken);
|
||||
channel = Channel.CreateSingleConsumerUnbounded<TSource>();
|
||||
|
||||
channelEnumerator = channel.Reader.ReadAllAsync().GetAsyncEnumerator(cancellationToken);
|
||||
|
||||
ConsumeAll(this, sourceEnumerator, channel).Forget();
|
||||
}
|
||||
|
||||
return channelEnumerator.MoveNextAsync();
|
||||
}
|
||||
|
||||
static async UniTaskVoid ConsumeAll(_Queue self, IUniTaskAsyncEnumerator<TSource> enumerator, ChannelWriter<TSource> writer)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (await enumerator.MoveNextAsync())
|
||||
{
|
||||
writer.TryWrite(enumerator.Current);
|
||||
}
|
||||
writer.TryComplete();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
writer.TryComplete(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
self.channelClosed = true;
|
||||
await enumerator.DisposeAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
if (sourceEnumerator != null)
|
||||
{
|
||||
await sourceEnumerator.DisposeAsync();
|
||||
}
|
||||
if (channelEnumerator != null)
|
||||
{
|
||||
await channelEnumerator.DisposeAsync();
|
||||
}
|
||||
|
||||
if (!channelClosed)
|
||||
{
|
||||
channelClosed = true;
|
||||
channel.Writer.TryComplete(new OperationCanceledException());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7ea1bcf9dbebb042bc99c7816249e02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -31,17 +31,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<int> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(start, end, cancellationToken);
|
||||
return new _Range(start, end, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<int>
|
||||
class _Range : IUniTaskAsyncEnumerator<int>
|
||||
{
|
||||
readonly int start;
|
||||
readonly int end;
|
||||
int current;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public Enumerator(int start, int end, CancellationToken cancellationToken)
|
||||
public _Range(int start, int end, CancellationToken cancellationToken)
|
||||
{
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
@@ -26,17 +26,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TElement> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(element, count, cancellationToken);
|
||||
return new _Repeat(element, count, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<TElement>
|
||||
class _Repeat : IUniTaskAsyncEnumerator<TElement>
|
||||
{
|
||||
readonly TElement element;
|
||||
readonly int count;
|
||||
int remaining;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public Enumerator(TElement element, int count, CancellationToken cancellationToken)
|
||||
public _Repeat(TElement element, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
this.element = element;
|
||||
this.count = count;
|
||||
|
||||
@@ -22,17 +22,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TValue> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(value, cancellationToken);
|
||||
return new _Return(value, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<TValue>
|
||||
class _Return : IUniTaskAsyncEnumerator<TValue>
|
||||
{
|
||||
readonly TValue value;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
bool called;
|
||||
|
||||
public Enumerator(TValue value, CancellationToken cancellationToken)
|
||||
public _Return(TValue value, CancellationToken cancellationToken)
|
||||
{
|
||||
this.value = value;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
@@ -25,10 +25,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _Reverse(source, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _Reverse : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
CancellationToken cancellationToken;
|
||||
@@ -36,10 +36,11 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
TSource[] array;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
public _Reverse(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -69,6 +70,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
return default;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(selector, nameof(selector));
|
||||
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectAwaitInt<TSource, TResult>(source, selector);
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectIntAwait<TSource, TResult>(source, selector);
|
||||
}
|
||||
|
||||
public static IUniTaskAsyncEnumerable<TResult> SelectAwaitWithCancellation<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector)
|
||||
@@ -43,7 +43,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(selector, nameof(selector));
|
||||
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectAwaitCancellation<TSource, TResult>(source, selector);
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectAwaitWithCancellation<TSource, TResult>(source, selector);
|
||||
}
|
||||
|
||||
public static IUniTaskAsyncEnumerable<TResult> SelectAwaitWithCancellation<TSource, TResult>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32, CancellationToken, UniTask<TResult>> selector)
|
||||
@@ -51,7 +51,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(selector, nameof(selector));
|
||||
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectAwaitIntCancellation<TSource, TResult>(source, selector);
|
||||
return new Cysharp.Threading.Tasks.Linq.SelectIntAwaitWithCancellation<TSource, TResult>(source, selector);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _Select(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorBase<TSource, TResult>
|
||||
sealed class _Select : AsyncEnumeratorBase<TSource, TResult>
|
||||
{
|
||||
readonly Func<TSource, TResult> selector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
public _Select(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -111,15 +111,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _SelectInt(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorBase<TSource, TResult>
|
||||
sealed class _SelectInt : AsyncEnumeratorBase<TSource, TResult>
|
||||
{
|
||||
readonly Func<TSource, int, TResult> selector;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, TResult> selector, CancellationToken cancellationToken)
|
||||
public _SelectInt(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, TResult> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -155,14 +155,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _SelectAwait(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
sealed class _SelectAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
{
|
||||
readonly Func<TSource, UniTask<TResult>> selector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public _SelectAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -176,18 +176,18 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
protected override bool TrySetCurrentCore(TResult awaitResult, out bool terminateIteration)
|
||||
{
|
||||
Current = awaitResult;
|
||||
terminateIteration= false;
|
||||
terminateIteration = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectAwaitInt<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
internal sealed class SelectIntAwait<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, int, UniTask<TResult>> selector;
|
||||
|
||||
public SelectAwaitInt(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<TResult>> selector)
|
||||
public SelectIntAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<TResult>> selector)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector = selector;
|
||||
@@ -195,15 +195,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _SelectIntAwait(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
sealed class _SelectIntAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
{
|
||||
readonly Func<TSource, int, UniTask<TResult>> selector;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public _SelectIntAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -217,18 +217,18 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
protected override bool TrySetCurrentCore(TResult awaitResult, out bool terminateIteration)
|
||||
{
|
||||
Current = awaitResult;
|
||||
terminateIteration= false;
|
||||
terminateIteration = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectAwaitCancellation<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
internal sealed class SelectAwaitWithCancellation<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, CancellationToken, UniTask<TResult>> selector;
|
||||
|
||||
public SelectAwaitCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector)
|
||||
public SelectAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector = selector;
|
||||
@@ -236,14 +236,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _SelectAwaitWithCancellation(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
sealed class _SelectAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
{
|
||||
readonly Func<TSource, CancellationToken, UniTask<TResult>> selector;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public _SelectAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -257,18 +257,18 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
protected override bool TrySetCurrentCore(TResult awaitResult, out bool terminateIteration)
|
||||
{
|
||||
Current = awaitResult;
|
||||
terminateIteration= false;
|
||||
terminateIteration = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SelectAwaitIntCancellation<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
internal sealed class SelectIntAwaitWithCancellation<TSource, TResult> : IUniTaskAsyncEnumerable<TResult>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly Func<TSource, int, CancellationToken, UniTask<TResult>> selector;
|
||||
|
||||
public SelectAwaitIntCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<TResult>> selector)
|
||||
public SelectIntAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<TResult>> selector)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector = selector;
|
||||
@@ -276,15 +276,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector, cancellationToken);
|
||||
return new _SelectIntAwaitWithCancellation(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
sealed class _SelectIntAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TResult, TResult>
|
||||
{
|
||||
readonly Func<TSource, int, CancellationToken, UniTask<TResult>> selector;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
public _SelectIntAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<TResult>> selector, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.selector = selector;
|
||||
@@ -298,7 +298,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
protected override bool TrySetCurrentCore(TResult awaitResult, out bool terminateIteration)
|
||||
{
|
||||
Current = awaitResult;
|
||||
terminateIteration= false;
|
||||
terminateIteration = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,10 +129,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
return new _SelectMany(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _SelectMany : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> sourceMoveNextCoreDelegate = SourceMoveNextCore;
|
||||
static readonly Action<object> selectedSourceMoveNextCoreDelegate = SeletedSourceMoveNextCore;
|
||||
@@ -153,13 +153,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<bool>.Awaiter selectedAwaiter;
|
||||
UniTask.Awaiter selectedDisposeAsyncAwaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, IUniTaskAsyncEnumerable<TCollection>> selector1, Func<TSource, int, IUniTaskAsyncEnumerable<TCollection>> selector2, Func<TSource, TCollection, TResult> resultSelector, CancellationToken cancellationToken)
|
||||
public _SelectMany(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, IUniTaskAsyncEnumerable<TCollection>> selector1, Func<TSource, int, IUniTaskAsyncEnumerable<TCollection>> selector2, Func<TSource, TCollection, TResult> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector1 = selector1;
|
||||
this.selector2 = selector2;
|
||||
this.resultSelector = resultSelector;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -232,7 +233,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectMany)state;
|
||||
|
||||
if (self.TryGetResult(self.sourceAwaiter, out var result))
|
||||
{
|
||||
@@ -267,7 +268,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SeletedSourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectMany)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedAwaiter, out var result))
|
||||
{
|
||||
@@ -311,7 +312,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SelectedEnumeratorDisposeAsyncCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectMany)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedDisposeAsyncAwaiter))
|
||||
{
|
||||
@@ -324,6 +325,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (selectedEnumerator != null)
|
||||
{
|
||||
await selectedEnumerator.DisposeAsync();
|
||||
@@ -361,10 +363,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
return new _SelectManyAwait(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _SelectManyAwait : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> sourceMoveNextCoreDelegate = SourceMoveNextCore;
|
||||
static readonly Action<object> selectedSourceMoveNextCoreDelegate = SeletedSourceMoveNextCore;
|
||||
@@ -391,13 +393,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<IUniTaskAsyncEnumerable<TCollection>>.Awaiter collectionSelectorAwaiter;
|
||||
UniTask<TResult>.Awaiter resultSelectorAwaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector1, Func<TSource, int, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector2, Func<TSource, TCollection, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
public _SelectManyAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector1, Func<TSource, int, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector2, Func<TSource, TCollection, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector1 = selector1;
|
||||
this.selector2 = selector2;
|
||||
this.resultSelector = resultSelector;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -470,7 +473,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.sourceAwaiter, out var result))
|
||||
{
|
||||
@@ -513,7 +516,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SeletedSourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedAwaiter, out var result))
|
||||
{
|
||||
@@ -563,7 +566,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SelectedEnumeratorDisposeAsyncCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedDisposeAsyncAwaiter))
|
||||
{
|
||||
@@ -576,7 +579,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SelectorAwaitCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.collectionSelectorAwaiter, out var result))
|
||||
{
|
||||
@@ -587,7 +590,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectorAwaitCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwait)state;
|
||||
|
||||
if (self.TryGetResult(self.resultSelectorAwaiter, out var result))
|
||||
{
|
||||
@@ -598,6 +601,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (selectedEnumerator != null)
|
||||
{
|
||||
await selectedEnumerator.DisposeAsync();
|
||||
@@ -635,10 +639,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TResult> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
return new _SelectManyAwaitWithCancellation(source, selector1, selector2, resultSelector, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
sealed class _SelectManyAwaitWithCancellation : MoveNextSource, IUniTaskAsyncEnumerator<TResult>
|
||||
{
|
||||
static readonly Action<object> sourceMoveNextCoreDelegate = SourceMoveNextCore;
|
||||
static readonly Action<object> selectedSourceMoveNextCoreDelegate = SeletedSourceMoveNextCore;
|
||||
@@ -665,13 +669,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
UniTask<IUniTaskAsyncEnumerable<TCollection>>.Awaiter collectionSelectorAwaiter;
|
||||
UniTask<TResult>.Awaiter resultSelectorAwaiter;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector1, Func<TSource, int, CancellationToken, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector2, Func<TSource, TCollection, CancellationToken, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
public _SelectManyAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector1, Func<TSource, int, CancellationToken, UniTask<IUniTaskAsyncEnumerable<TCollection>>> selector2, Func<TSource, TCollection, CancellationToken, UniTask<TResult>> resultSelector, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.selector1 = selector1;
|
||||
this.selector2 = selector2;
|
||||
this.resultSelector = resultSelector;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TResult Current { get; private set; }
|
||||
@@ -744,7 +749,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.sourceAwaiter, out var result))
|
||||
{
|
||||
@@ -787,7 +792,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SeletedSourceMoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedAwaiter, out var result))
|
||||
{
|
||||
@@ -837,7 +842,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SelectedEnumeratorDisposeAsyncCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.selectedDisposeAsyncAwaiter))
|
||||
{
|
||||
@@ -850,7 +855,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void SelectorAwaitCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.collectionSelectorAwaiter, out var result))
|
||||
{
|
||||
@@ -861,7 +866,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void ResultSelectorAwaitCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SelectManyAwaitWithCancellation)state;
|
||||
|
||||
if (self.TryGetResult(self.resultSelectorAwaiter, out var result))
|
||||
{
|
||||
@@ -872,6 +877,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public async UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (selectedEnumerator != null)
|
||||
{
|
||||
await selectedEnumerator.DisposeAsync();
|
||||
|
||||
@@ -18,13 +18,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(second, nameof(second));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return SequenceEqual.InvokeAsync(first, second, comparer, cancellationToken);
|
||||
return SequenceEqual.SequenceEqualAsync(first, second, comparer, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class SequenceEqual
|
||||
{
|
||||
internal static async UniTask<bool> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<bool> SequenceEqualAsync<TSource>(IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var e1 = first.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, cancellationToken, false);
|
||||
return SingleOperator.SingleAsync(source, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return SingleOperator.SingleAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -26,7 +26,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return SingleOperator.SingleAwaitAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -34,14 +34,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, false);
|
||||
return SingleOperator.SingleAwaitWithCancellationAsync(source, predicate, cancellationToken, false);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, cancellationToken, true);
|
||||
return SingleOperator.SingleAsync(source, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleOrDefaultAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return SingleOperator.SingleAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleOrDefaultAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return SingleOperator.SingleAwaitAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
|
||||
public static UniTask<TSource> SingleOrDefaultAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken = default)
|
||||
@@ -65,13 +65,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(predicate, nameof(predicate));
|
||||
|
||||
return SingleOperator.InvokeAsync(source, predicate, cancellationToken, true);
|
||||
return SingleOperator.SingleAwaitWithCancellationAsync(source, predicate, cancellationToken, true);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class SingleOperator
|
||||
{
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> SingleAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -107,7 +107,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> SingleAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Boolean> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -147,7 +147,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> SingleAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
@@ -187,7 +187,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
public static async UniTask<TSource> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
public static async UniTask<TSource> SingleAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Boolean>> predicate, CancellationToken cancellationToken, bool defaultIfEmpty)
|
||||
{
|
||||
var e = source.GetAsyncEnumerator(cancellationToken);
|
||||
try
|
||||
|
||||
@@ -27,16 +27,16 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, cancellationToken);
|
||||
return new _Skip(source, count, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
sealed class _Skip : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly int count;
|
||||
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
public _Skip(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.count = count;
|
||||
|
||||
@@ -34,10 +34,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, cancellationToken);
|
||||
return new _SkipLast(source, count, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _SkipLast : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -51,11 +51,12 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
bool continueNext;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
public _SkipLast(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.count = count;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -106,7 +107,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_SkipLast)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -146,6 +147,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IUniTaskAsyncEnumerable<TSource> SkipUntilCanceled<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return new SkipUntilCanceled<TSource>(source, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class SkipUntilCanceled<TSource> : IUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly CancellationToken cancellationToken;
|
||||
|
||||
public SkipUntilCanceled(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _SkipUntilCanceled(source, this.cancellationToken, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class _SkipUntilCanceled : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
CancellationToken cancellationToken1;
|
||||
CancellationToken cancellationToken2;
|
||||
|
||||
bool isCanceled;
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
bool continueNext;
|
||||
|
||||
public _SkipUntilCanceled(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken1, CancellationToken cancellationToken2)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken1 = cancellationToken1;
|
||||
this.cancellationToken2 = cancellationToken2;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
if (cancellationToken1.IsCancellationRequested) isCanceled = true;
|
||||
if (cancellationToken2.IsCancellationRequested) isCanceled = true;
|
||||
|
||||
if (enumerator == null)
|
||||
{
|
||||
enumerator = source.GetAsyncEnumerator(cancellationToken2); // use only AsyncEnumerator provided token.
|
||||
}
|
||||
completionSource.Reset();
|
||||
SourceMoveNext();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
void SourceMoveNext()
|
||||
{
|
||||
try
|
||||
{
|
||||
LOOP:
|
||||
awaiter = enumerator.MoveNextAsync().GetAwaiter();
|
||||
if (awaiter.IsCompleted)
|
||||
{
|
||||
continueNext = true;
|
||||
MoveNextCore(this);
|
||||
if (continueNext)
|
||||
{
|
||||
continueNext = false;
|
||||
goto LOOP;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (_SkipUntilCanceled)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
AGAIN:
|
||||
|
||||
if (self.isCanceled)
|
||||
{
|
||||
self.continueNext = false;
|
||||
self.Current = self.enumerator.Current;
|
||||
self.completionSource.TrySetResult(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self.cancellationToken1.IsCancellationRequested) self.isCanceled = true;
|
||||
if (self.cancellationToken2.IsCancellationRequested) self.isCanceled = true;
|
||||
|
||||
if (self.isCanceled) goto AGAIN;
|
||||
|
||||
if (!self.continueNext)
|
||||
{
|
||||
self.SourceMoveNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4b1a778aef7150d47b93a49aa1bc34ae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -68,14 +68,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhile(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _SkipWhile : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
Func<TSource, bool> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhile(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -119,15 +119,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhileInt(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _SkipWhileInt : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
Func<TSource, int, bool> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhileInt(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -171,14 +171,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhileAwait(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _SkipWhileAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, UniTask<bool>> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhileAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -226,15 +226,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhileIntAwait(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _SkipWhileIntAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, int, UniTask<bool>> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhileIntAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -281,14 +281,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhileAwaitWithCancellation(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _SkipWhileAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, CancellationToken, UniTask<bool>> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhileAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -335,15 +335,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _SkipWhileIntAwaitWithCancellation(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _SkipWhileIntAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, int, CancellationToken, UniTask<bool>> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _SkipWhileIntAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken = default)
|
||||
@@ -18,7 +18,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -26,22 +26,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Int32> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64> SumAsync(this IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken = default)
|
||||
@@ -49,7 +49,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -57,22 +57,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Int64> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single> SumAsync(this IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken = default)
|
||||
@@ -80,7 +80,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -88,22 +88,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Single> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double> SumAsync(this IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken = default)
|
||||
@@ -111,7 +111,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -119,22 +119,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Double> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal> SumAsync(this IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken = default)
|
||||
@@ -142,7 +142,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -150,22 +150,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Decimal> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32?> SumAsync(this IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32?> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -173,7 +173,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32?> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -181,22 +181,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int32?> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Int32?> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64?> SumAsync(this IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64?> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -204,7 +204,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64?> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -212,22 +212,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Int64?> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Int64?> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single?> SumAsync(this IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single?> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -235,7 +235,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single?> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -243,22 +243,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Single?> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Single?> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double?> SumAsync(this IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double?> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -266,7 +266,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double?> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -274,22 +274,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Double?> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Double?> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal?> SumAsync(this IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal?> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken = default)
|
||||
@@ -297,7 +297,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal?> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -305,22 +305,22 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Decimal?> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<Decimal?> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static class Sum
|
||||
{
|
||||
public static async UniTask<Int32> InvokeAsync(IUniTaskAsyncEnumerable<Int32> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32> SumAsync(IUniTaskAsyncEnumerable<Int32> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32 sum = default;
|
||||
|
||||
@@ -343,7 +343,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32 sum = default;
|
||||
|
||||
@@ -366,7 +366,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32 sum = default;
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32 sum = default;
|
||||
|
||||
@@ -412,7 +412,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64> InvokeAsync(IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64> SumAsync(IUniTaskAsyncEnumerable<Int64> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64 sum = default;
|
||||
|
||||
@@ -435,7 +435,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64 sum = default;
|
||||
|
||||
@@ -458,7 +458,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64 sum = default;
|
||||
|
||||
@@ -481,7 +481,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64 sum = default;
|
||||
|
||||
@@ -504,7 +504,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single> InvokeAsync(IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single> SumAsync(IUniTaskAsyncEnumerable<Single> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Single sum = default;
|
||||
|
||||
@@ -527,7 +527,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single sum = default;
|
||||
|
||||
@@ -550,7 +550,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single sum = default;
|
||||
|
||||
@@ -573,7 +573,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single sum = default;
|
||||
|
||||
@@ -596,7 +596,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double> InvokeAsync(IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double> SumAsync(IUniTaskAsyncEnumerable<Double> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Double sum = default;
|
||||
|
||||
@@ -619,7 +619,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double sum = default;
|
||||
|
||||
@@ -642,7 +642,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double sum = default;
|
||||
|
||||
@@ -665,7 +665,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double sum = default;
|
||||
|
||||
@@ -688,7 +688,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal> InvokeAsync(IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal> SumAsync(IUniTaskAsyncEnumerable<Decimal> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal sum = default;
|
||||
|
||||
@@ -711,7 +711,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal sum = default;
|
||||
|
||||
@@ -734,7 +734,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal sum = default;
|
||||
|
||||
@@ -757,7 +757,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal sum = default;
|
||||
|
||||
@@ -780,7 +780,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32?> InvokeAsync(IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32?> SumAsync(IUniTaskAsyncEnumerable<Int32?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32? sum = default;
|
||||
|
||||
@@ -803,7 +803,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32?> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int32?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32? sum = default;
|
||||
|
||||
@@ -826,7 +826,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32?> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32? sum = default;
|
||||
|
||||
@@ -849,7 +849,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int32?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int32?> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int32?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int32? sum = default;
|
||||
|
||||
@@ -872,7 +872,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64?> InvokeAsync(IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64?> SumAsync(IUniTaskAsyncEnumerable<Int64?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64? sum = default;
|
||||
|
||||
@@ -895,7 +895,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64?> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Int64?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64? sum = default;
|
||||
|
||||
@@ -918,7 +918,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64?> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64? sum = default;
|
||||
|
||||
@@ -941,7 +941,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Int64?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Int64?> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Int64?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Int64? sum = default;
|
||||
|
||||
@@ -964,7 +964,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single?> InvokeAsync(IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single?> SumAsync(IUniTaskAsyncEnumerable<Single?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Single? sum = default;
|
||||
|
||||
@@ -987,7 +987,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single?> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Single?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single? sum = default;
|
||||
|
||||
@@ -1010,7 +1010,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single?> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single? sum = default;
|
||||
|
||||
@@ -1033,7 +1033,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Single?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Single?> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Single?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Single? sum = default;
|
||||
|
||||
@@ -1056,7 +1056,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double?> InvokeAsync(IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double?> SumAsync(IUniTaskAsyncEnumerable<Double?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Double? sum = default;
|
||||
|
||||
@@ -1079,7 +1079,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double?> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Double?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double? sum = default;
|
||||
|
||||
@@ -1102,7 +1102,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double?> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double? sum = default;
|
||||
|
||||
@@ -1125,7 +1125,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Double?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Double?> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Double?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Double? sum = default;
|
||||
|
||||
@@ -1148,7 +1148,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal?> InvokeAsync(IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal?> SumAsync(IUniTaskAsyncEnumerable<Decimal?> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal? sum = default;
|
||||
|
||||
@@ -1171,7 +1171,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal?> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, Decimal?> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal? sum = default;
|
||||
|
||||
@@ -1194,7 +1194,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal?> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal? sum = default;
|
||||
|
||||
@@ -1217,7 +1217,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<Decimal?> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<Decimal?> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<Decimal?>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
Decimal? sum = default;
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Sum.InvokeAsync(source, cancellationToken);
|
||||
return Sum.SumAsync(source, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> SumAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -45,7 +45,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> SumAwaitAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
@@ -53,15 +53,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<<#= TypeName(t) #>> SumAwaitCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
public static UniTask<<#= TypeName(t) #>> SumAwaitWithCancellationAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken = default)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(source, nameof(selector));
|
||||
|
||||
return Sum.InvokeAsync(source, selector, cancellationToken);
|
||||
return Sum.SumAwaitWithCancellationAsync(source, selector, cancellationToken);
|
||||
}
|
||||
|
||||
<# } #>
|
||||
@@ -70,7 +70,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
internal static class Sum
|
||||
{
|
||||
<# foreach(var t in types) { #>
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> SumAsync(IUniTaskAsyncEnumerable<<#= TypeName(t) #>> source, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> sum = default;
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> SumAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, <#= TypeName(t) #>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> sum = default;
|
||||
|
||||
@@ -116,7 +116,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> SumAwaitAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> sum = default;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return sum;
|
||||
}
|
||||
|
||||
public static async UniTask<<#= TypeName(t) #>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
public static async UniTask<<#= TypeName(t) #>> SumAwaitWithCancellationAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<<#= TypeName(t) #>>> selector, CancellationToken cancellationToken)
|
||||
{
|
||||
<#= TypeName(t) #> sum = default;
|
||||
|
||||
|
||||
@@ -27,43 +27,98 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, cancellationToken);
|
||||
return new _Take(source, count, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
sealed class _Take : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
readonly int count;
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly int count;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
public _Take(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.count = count;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
protected override bool TryMoveNextCore(bool sourceHasCurrent, out bool result)
|
||||
public TSource Current { get; private set; }
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
if (sourceHasCurrent)
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
if (enumerator == null)
|
||||
{
|
||||
if (checked(index++) < count)
|
||||
enumerator = source.GetAsyncEnumerator(cancellationToken);
|
||||
}
|
||||
|
||||
if (checked(index) >= count)
|
||||
{
|
||||
return CompletedTasks.False;
|
||||
}
|
||||
|
||||
completionSource.Reset();
|
||||
SourceMoveNext();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
void SourceMoveNext()
|
||||
{
|
||||
try
|
||||
{
|
||||
awaiter = enumerator.MoveNextAsync().GetAwaiter();
|
||||
if (awaiter.IsCompleted)
|
||||
{
|
||||
Current = SourceCurrent;
|
||||
result = true;
|
||||
return true;
|
||||
MoveNextCore(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = false;
|
||||
return true;
|
||||
awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
|
||||
}
|
||||
}
|
||||
else
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = false;
|
||||
return true;
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (_Take)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
self.index++;
|
||||
self.Current = self.enumerator.Current;
|
||||
self.completionSource.TrySetResult(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,10 +34,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, count, cancellationToken);
|
||||
return new _TakeLast(source, count, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
sealed class _TakeLast : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
@@ -52,11 +52,12 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
bool iterateCompleted;
|
||||
bool continueNext;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
public _TakeLast(IUniTaskAsyncEnumerable<TSource> source, int count, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.count = count;
|
||||
this.cancellationToken = cancellationToken;
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
@@ -121,7 +122,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_TakeLast)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
@@ -162,6 +163,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
public static partial class UniTaskAsyncEnumerable
|
||||
{
|
||||
public static IUniTaskAsyncEnumerable<TSource> TakeUntilCanceled<TSource>(this IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return new TakeUntilCanceled<TSource>(source, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class TakeUntilCanceled<TSource> : IUniTaskAsyncEnumerable<TSource>
|
||||
{
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
readonly CancellationToken cancellationToken;
|
||||
|
||||
public TakeUntilCanceled(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
}
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new _TakeUntilCanceled(source, this.cancellationToken, cancellationToken);
|
||||
}
|
||||
|
||||
sealed class _TakeUntilCanceled : MoveNextSource, IUniTaskAsyncEnumerator<TSource>
|
||||
{
|
||||
static readonly Action<object> CancelDelegate1 = OnCanceled1;
|
||||
static readonly Action<object> CancelDelegate2 = OnCanceled2;
|
||||
static readonly Action<object> MoveNextCoreDelegate = MoveNextCore;
|
||||
|
||||
readonly IUniTaskAsyncEnumerable<TSource> source;
|
||||
CancellationToken cancellationToken1;
|
||||
CancellationToken cancellationToken2;
|
||||
CancellationTokenRegistration cancellationTokenRegistration1;
|
||||
CancellationTokenRegistration cancellationTokenRegistration2;
|
||||
|
||||
bool isCanceled;
|
||||
IUniTaskAsyncEnumerator<TSource> enumerator;
|
||||
UniTask<bool>.Awaiter awaiter;
|
||||
|
||||
public _TakeUntilCanceled(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken1, CancellationToken cancellationToken2)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken1 = cancellationToken1;
|
||||
this.cancellationToken2 = cancellationToken2;
|
||||
|
||||
if (cancellationToken1.CanBeCanceled)
|
||||
{
|
||||
this.cancellationTokenRegistration1 = cancellationToken1.RegisterWithoutCaptureExecutionContext(CancelDelegate1, this);
|
||||
}
|
||||
|
||||
if (cancellationToken1 != cancellationToken2 && cancellationToken2.CanBeCanceled)
|
||||
{
|
||||
this.cancellationTokenRegistration2 = cancellationToken2.RegisterWithoutCaptureExecutionContext(CancelDelegate2, this);
|
||||
}
|
||||
TaskTracker.TrackActiveTask(this, 3);
|
||||
}
|
||||
|
||||
public TSource Current { get; private set; }
|
||||
|
||||
public UniTask<bool> MoveNextAsync()
|
||||
{
|
||||
if (cancellationToken1.IsCancellationRequested) isCanceled = true;
|
||||
if (cancellationToken2.IsCancellationRequested) isCanceled = true;
|
||||
|
||||
if (enumerator == null)
|
||||
{
|
||||
enumerator = source.GetAsyncEnumerator(cancellationToken2); // use only AsyncEnumerator provided token.
|
||||
}
|
||||
|
||||
if (isCanceled) return CompletedTasks.False;
|
||||
|
||||
completionSource.Reset();
|
||||
SourceMoveNext();
|
||||
return new UniTask<bool>(this, completionSource.Version);
|
||||
}
|
||||
|
||||
void SourceMoveNext()
|
||||
{
|
||||
try
|
||||
{
|
||||
awaiter = enumerator.MoveNextAsync().GetAwaiter();
|
||||
if (awaiter.IsCompleted)
|
||||
{
|
||||
MoveNextCore(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
awaiter.SourceOnCompleted(MoveNextCoreDelegate, this);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
completionSource.TrySetException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void MoveNextCore(object state)
|
||||
{
|
||||
var self = (_TakeUntilCanceled)state;
|
||||
|
||||
if (self.TryGetResult(self.awaiter, out var result))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
if (self.isCanceled)
|
||||
{
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
self.Current = self.enumerator.Current;
|
||||
self.completionSource.TrySetResult(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void OnCanceled1(object state)
|
||||
{
|
||||
var self = (_TakeUntilCanceled)state;
|
||||
if (!self.isCanceled)
|
||||
{
|
||||
self.cancellationTokenRegistration2.Dispose();
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
static void OnCanceled2(object state)
|
||||
{
|
||||
var self = (_TakeUntilCanceled)state;
|
||||
if (!self.isCanceled)
|
||||
{
|
||||
self.cancellationTokenRegistration1.Dispose();
|
||||
self.completionSource.TrySetResult(false);
|
||||
}
|
||||
}
|
||||
|
||||
public UniTask DisposeAsync()
|
||||
{
|
||||
TaskTracker.RemoveTracking(this);
|
||||
cancellationTokenRegistration1.Dispose();
|
||||
cancellationTokenRegistration2.Dispose();
|
||||
if (enumerator != null)
|
||||
{
|
||||
return enumerator.DisposeAsync();
|
||||
}
|
||||
return default;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e82f498cf3a1df04cbf646773fc11319
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -68,14 +68,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhile(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _TakeWhile : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
Func<TSource, bool> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhile(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -113,15 +113,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhileInt(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorBase<TSource, TSource>
|
||||
class _TakeWhileInt : AsyncEnumeratorBase<TSource, TSource>
|
||||
{
|
||||
readonly Func<TSource, int, bool> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhileInt(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, bool> predicate, CancellationToken cancellationToken)
|
||||
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
@@ -159,14 +159,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhileAwait(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _TakeWhileAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, UniTask<bool>> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhileAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
@@ -207,15 +207,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhileIntAwait(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _TakeWhileIntAwait : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
readonly Func<TSource, int, UniTask<bool>> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhileIntAwait(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
@@ -256,14 +256,14 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhileAwaitWithCancellation(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _TakeWhileAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
Func<TSource, CancellationToken, UniTask<bool>> predicate;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhileAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
@@ -304,15 +304,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TSource> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, predicate, cancellationToken);
|
||||
return new _TakeWhileIntAwaitWithCancellation(source, predicate, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
class _TakeWhileIntAwaitWithCancellation : AsyncEnumeratorAwaitSelectorBase<TSource, TSource, bool>
|
||||
{
|
||||
readonly Func<TSource, int, CancellationToken, UniTask<bool>> predicate;
|
||||
int index;
|
||||
|
||||
public Enumerator(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
public _TakeWhileIntAwaitWithCancellation(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, int, CancellationToken, UniTask<bool>> predicate, CancellationToken cancellationToken)
|
||||
: base(source, cancellationToken)
|
||||
{
|
||||
this.predicate = predicate;
|
||||
|
||||
@@ -23,15 +23,15 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<TValue> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(exception, cancellationToken);
|
||||
return new _Throw(exception, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<TValue>
|
||||
class _Throw : IUniTaskAsyncEnumerator<TValue>
|
||||
{
|
||||
readonly Exception exception;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
public Enumerator(Exception exception, CancellationToken cancellationToken)
|
||||
public _Throw(Exception exception, CancellationToken cancellationToken)
|
||||
{
|
||||
this.exception = exception;
|
||||
this.cancellationToken = cancellationToken;
|
||||
|
||||
@@ -11,13 +11,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ToArray.InvokeAsync(source, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ToArray.ToArrayAsync(source, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ToArray
|
||||
{
|
||||
internal static async UniTask<TSource[]> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
internal static async UniTask<TSource[]> ToArrayAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -21,7 +21,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -30,7 +30,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -40,7 +40,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, CancellationToken cancellationToken = default)
|
||||
@@ -48,7 +48,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -57,7 +57,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -66,7 +66,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -76,7 +76,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, CancellationToken cancellationToken = default)
|
||||
@@ -84,7 +84,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitWithCancellationAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -93,7 +93,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitWithCancellationAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -102,7 +102,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitWithCancellationAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -112,13 +112,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToDictionary.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToDictionary.ToDictionaryAwaitWithCancellationAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ToDictionary
|
||||
{
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TSource>(comparer);
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TElement>(comparer);
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with await
|
||||
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TSource>(comparer);
|
||||
|
||||
@@ -196,7 +196,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TElement>(comparer);
|
||||
|
||||
@@ -224,7 +224,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with cancellation
|
||||
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TSource>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TSource>(comparer);
|
||||
|
||||
@@ -249,7 +249,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
return dict;
|
||||
}
|
||||
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<Dictionary<TKey, TElement>> ToDictionaryAwaitWithCancellationAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var dict = new Dictionary<TKey, TElement>(comparer);
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ToHashSet.InvokeAsync(source, EqualityComparer<TSource>.Default, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ToHashSet.ToHashSetAsync(source, EqualityComparer<TSource>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<HashSet<TSource>> ToHashSetAsync<TSource>(this IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -18,13 +18,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ToHashSet.InvokeAsync(source, comparer, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ToHashSet.ToHashSetAsync(source, comparer, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ToHashSet
|
||||
{
|
||||
internal static async UniTask<HashSet<TSource>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<HashSet<TSource>> ToHashSetAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var set = new HashSet<TSource>(comparer);
|
||||
|
||||
|
||||
@@ -10,13 +10,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
|
||||
return Cysharp.Threading.Tasks.Linq.ToList.InvokeAsync(source, cancellationToken);
|
||||
return Cysharp.Threading.Tasks.Linq.ToList.ToListAsync(source, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ToList
|
||||
{
|
||||
internal static async UniTask<List<TSource>> InvokeAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
internal static async UniTask<List<TSource>> ToListAsync<TSource>(IUniTaskAsyncEnumerable<TSource> source, CancellationToken cancellationToken)
|
||||
{
|
||||
var list = new List<TSource>();
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -23,7 +23,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -32,7 +32,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -42,7 +42,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TSource>> ToLookupAwaitAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, CancellationToken cancellationToken = default)
|
||||
@@ -50,7 +50,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TSource>> ToLookupAwaitAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -59,7 +59,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAwaitAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -68,7 +68,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAwaitAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -78,7 +78,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, CancellationToken cancellationToken = default)
|
||||
@@ -86,7 +86,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(source, nameof(source));
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitWithCancellationAsync(source, keySelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsync<TSource, TKey>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -95,7 +95,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitWithCancellationAsync(source, keySelector, comparer, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, CancellationToken cancellationToken = default)
|
||||
@@ -104,7 +104,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(keySelector, nameof(keySelector));
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitWithCancellationAsync(source, keySelector, elementSelector, EqualityComparer<TKey>.Default, cancellationToken);
|
||||
}
|
||||
|
||||
public static UniTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsync<TSource, TKey, TElement>(this IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
|
||||
@@ -114,13 +114,13 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
Error.ThrowArgumentNullException(elementSelector, nameof(elementSelector));
|
||||
Error.ThrowArgumentNullException(comparer, nameof(comparer));
|
||||
|
||||
return ToLookup.InvokeAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
return ToLookup.ToLookupAwaitWithCancellationAsync(source, keySelector, elementSelector, comparer, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class ToLookup
|
||||
{
|
||||
internal static async UniTask<ILookup<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
@@ -155,7 +155,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<ILookup<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
@@ -194,7 +194,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with await
|
||||
|
||||
internal static async UniTask<ILookup<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TSource>> ToLookupAwaitAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
@@ -230,7 +230,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<ILookup<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TElement>> ToLookupAwaitAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, UniTask<TKey>> keySelector, Func<TSource, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
@@ -268,7 +268,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
// with cancellation
|
||||
|
||||
internal static async UniTask<ILookup<TKey, TSource>> InvokeAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TSource>> ToLookupAwaitWithCancellationAsync<TSource, TKey>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
@@ -304,7 +304,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
}
|
||||
}
|
||||
|
||||
internal static async UniTask<ILookup<TKey, TElement>> InvokeAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
internal static async UniTask<ILookup<TKey, TElement>> ToLookupAwaitWithCancellationAsync<TSource, TKey, TElement>(IUniTaskAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, UniTask<TKey>> keySelector, Func<TSource, CancellationToken, UniTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
|
||||
{
|
||||
var pool = ArrayPool<TSource>.Shared;
|
||||
var array = pool.Rent(16);
|
||||
|
||||
@@ -48,17 +48,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _ToUniTaskAsyncEnumerable(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<T>
|
||||
class _ToUniTaskAsyncEnumerable : IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
readonly IEnumerable<T> source;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
IEnumerator<T> enumerator;
|
||||
|
||||
public Enumerator(IEnumerable<T> source, CancellationToken cancellationToken)
|
||||
public _ToUniTaskAsyncEnumerable(IEnumerable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
@@ -102,10 +102,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _ToUniTaskAsyncEnumerableTask(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<T>
|
||||
class _ToUniTaskAsyncEnumerableTask : IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
readonly Task<T> source;
|
||||
CancellationToken cancellationToken;
|
||||
@@ -113,7 +113,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
T current;
|
||||
bool called;
|
||||
|
||||
public Enumerator(Task<T> source, CancellationToken cancellationToken)
|
||||
public _ToUniTaskAsyncEnumerableTask(Task<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
@@ -155,10 +155,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _ToUniTaskAsyncEnumerableUniTask(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : IUniTaskAsyncEnumerator<T>
|
||||
class _ToUniTaskAsyncEnumerableUniTask : IUniTaskAsyncEnumerator<T>
|
||||
{
|
||||
readonly UniTask<T> source;
|
||||
CancellationToken cancellationToken;
|
||||
@@ -166,7 +166,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
T current;
|
||||
bool called;
|
||||
|
||||
public Enumerator(UniTask<T> source, CancellationToken cancellationToken)
|
||||
public _ToUniTaskAsyncEnumerableUniTask(UniTask<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
@@ -208,10 +208,10 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(source, cancellationToken);
|
||||
return new _ToUniTaskAsyncEnumerableObservable(source, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<T>, IObserver<T>
|
||||
class _ToUniTaskAsyncEnumerableObservable : MoveNextSource, IUniTaskAsyncEnumerator<T>, IObserver<T>
|
||||
{
|
||||
static readonly Action<object> OnCanceledDelegate = OnCanceled;
|
||||
|
||||
@@ -227,7 +227,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
IDisposable subscription;
|
||||
CancellationTokenRegistration cancellationTokenRegistration;
|
||||
|
||||
public Enumerator(IObservable<T> source, CancellationToken cancellationToken)
|
||||
public _ToUniTaskAsyncEnumerableObservable(IObservable<T> source, CancellationToken cancellationToken)
|
||||
{
|
||||
this.source = source;
|
||||
this.cancellationToken = cancellationToken;
|
||||
@@ -334,7 +334,7 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
static void OnCanceled(object state)
|
||||
{
|
||||
var self = (Enumerator)state;
|
||||
var self = (_ToUniTaskAsyncEnumerableObservable)state;
|
||||
lock (self.queuedResult)
|
||||
{
|
||||
self.completionSource.TrySetCanceled(self.cancellationToken);
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using Cysharp.Threading.Tasks.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading;
|
||||
|
||||
namespace Cysharp.Threading.Tasks.Linq
|
||||
{
|
||||
@@ -24,17 +21,17 @@ namespace Cysharp.Threading.Tasks.Linq
|
||||
|
||||
public IUniTaskAsyncEnumerator<AsyncUnit> GetAsyncEnumerator(CancellationToken cancellationToken = default)
|
||||
{
|
||||
return new Enumerator(updateTiming, cancellationToken);
|
||||
return new _EveryUpdate(updateTiming, cancellationToken);
|
||||
}
|
||||
|
||||
class Enumerator : MoveNextSource, IUniTaskAsyncEnumerator<AsyncUnit>, IPlayerLoopItem
|
||||
class _EveryUpdate : MoveNextSource, IUniTaskAsyncEnumerator<AsyncUnit>, IPlayerLoopItem
|
||||
{
|
||||
readonly PlayerLoopTiming updateTiming;
|
||||
CancellationToken cancellationToken;
|
||||
|
||||
bool disposed;
|
||||
|
||||
public Enumerator(PlayerLoopTiming updateTiming, CancellationToken cancellationToken)
|
||||
public _EveryUpdate(PlayerLoopTiming updateTiming, CancellationToken cancellationToken)
|
||||
{
|
||||
this.updateTiming = updateTiming;
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user