Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
overhaul UniRx.Async, introduce IAwaitable<T>, IAwaiter<T> and suppor…
…t with WhenAll/WhenAny
  • Loading branch information
neuecc committed Jul 18, 2018
1 parent 0870445 commit 496f28b
Show file tree
Hide file tree
Showing 19 changed files with 6,676 additions and 297 deletions.
21 changes: 21 additions & 0 deletions Assembly-CSharp-firstpass.csproj
Expand Up @@ -86,6 +86,27 @@
<Reference Include="Unity.TextMeshPro">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="Unity.ScriptableBuildPipeline.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ScriptableBuildPipeline.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.ResourceManager">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Unity.Addressables.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.Addressables.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.ResourceManager.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ResourceManager.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.Addressables">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.Addressables.dll</HintPath>
</Reference>
<Reference Include="Unity.CacheServer.Client.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.CacheServer.Client.Editor.dll</HintPath>
</Reference>
<Reference Include="com.unity.resourcemanager">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/com.unity.resourcemanager.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AIModule">
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.2.0f2/Editor/Data/Managed/UnityEngine/UnityEngine.AIModule.dll</HintPath>
</Reference>
Expand Down
21 changes: 21 additions & 0 deletions Assembly-CSharp.csproj
Expand Up @@ -84,6 +84,27 @@
<Reference Include="Unity.TextMeshPro">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.TextMeshPro.dll</HintPath>
</Reference>
<Reference Include="Unity.ScriptableBuildPipeline.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ScriptableBuildPipeline.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.ResourceManager">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ResourceManager.dll</HintPath>
</Reference>
<Reference Include="Unity.Addressables.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.Addressables.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.ResourceManager.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.ResourceManager.Editor.dll</HintPath>
</Reference>
<Reference Include="Unity.Addressables">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.Addressables.dll</HintPath>
</Reference>
<Reference Include="Unity.CacheServer.Client.Editor">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/Unity.CacheServer.Client.Editor.dll</HintPath>
</Reference>
<Reference Include="com.unity.resourcemanager">
<HintPath>C:/Users/S02811/Documents/UniRx/Library/ScriptAssemblies/com.unity.resourcemanager.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.AIModule">
<HintPath>C:/Program Files/Unity/Hub/Editor/2018.2.0f2/Editor/Data/Managed/UnityEngine/UnityEngine.AIModule.dll</HintPath>
</Reference>
Expand Down
11 changes: 5 additions & 6 deletions Assets/Plugins/UniRx/Scripts/Async/EnumeratorAsyncExtensions.cs
Expand Up @@ -3,27 +3,26 @@

using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;

namespace UniRx.Async
{
public static class EnumeratorAsyncExtensions
{
public static EnumeratorAwaiter GetAwaiter(this IEnumerator enumerator)
public static IAwaiter GetAwaiter(this IEnumerator enumerator)
{
return enumerator.ConfigureAwait();
return enumerator.ConfigureAwait().GetAwaiter();
}

public static EnumeratorAwaiter ConfigureAwait(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
public static IAwaitable ConfigureAwait(this IEnumerator enumerator, PlayerLoopTiming timing = PlayerLoopTiming.Update, CancellationToken cancellationToken = default(CancellationToken))
{
var awaiter = new EnumeratorAwaiter(enumerator, cancellationToken);
PlayerLoopHelper.AddAction(timing, awaiter);
return awaiter;
}

public class EnumeratorAwaiter : ICriticalNotifyCompletion, IPlayerLoopItem
class EnumeratorAwaiter : IAwaitable, IAwaiter, IPlayerLoopItem
{
const int Unfinished = 0;
const int Success = 1;
Expand All @@ -44,7 +43,7 @@ public EnumeratorAwaiter(IEnumerator innerEnumerator, CancellationToken cancella
this.cancellationToken = cancellationToken;
}

public EnumeratorAwaiter GetAwaiter()
public IAwaiter GetAwaiter()
{
return this;
}
Expand Down
34 changes: 34 additions & 0 deletions Assets/Plugins/UniRx/Scripts/Async/IAwaitable.cs
@@ -0,0 +1,34 @@
#if (NET_4_6 || NET_STANDARD_2_0)
#pragma warning disable CS1591

using System.Runtime.CompilerServices;

namespace UniRx.Async
{
// This interfaces used by UniTask.WhenAll/WhenAny
// If implement this interface and if awaiter/awaitable can be struct,
// use explicit-interface-implementation.

public interface IAwaitable
{
IAwaiter GetAwaiter();
}

public interface IAwaitable<out T> : IAwaitable
{
new IAwaiter<T> GetAwaiter();
}

public interface IAwaiter : ICriticalNotifyCompletion
{
bool IsCompleted { get; }
void GetResult();
}

public interface IAwaiter<out T> : IAwaiter
{
new T GetResult();
}
}

#endif
11 changes: 11 additions & 0 deletions Assets/Plugins/UniRx/Scripts/Async/IAwaitable.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions Assets/Plugins/UniRx/Scripts/Async/UniRx.Async.asmdef
@@ -1,3 +1,8 @@
{
"name": "UniRx.Async"
}
{
"name": "UniRx.Async",
"references": [],
"optionalUnityReferences": [],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false
}

0 comments on commit 496f28b

Please sign in to comment.