simplify UNITASK define

pull/541/head
neuecc 2024-01-25 20:42:42 +09:00
parent 0ef6c59385
commit 08184af737
6 changed files with 67 additions and 50 deletions

View File

@ -5,6 +5,7 @@
<AssemblyName>UniTask</AssemblyName>
<LangVersion>8.0</LangVersion>
<RootNamespace>Cysharp.Threading.Tasks</RootNamespace>
<DefineConstants>UNITASK_NETCORE</DefineConstants>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>

View File

@ -1,3 +1,5 @@
#pragma warning disable CS1998
using System;
using System.Threading;
using System.Threading.Tasks;

View File

@ -1,3 +1,5 @@
#pragma warning disable CS1998
using System;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;

View File

@ -1,4 +1,9 @@
#pragma warning disable CS1591
#pragma warning disable CS0108
#if (UNITASK_NETCORE && !NETSTANDARD2_0) || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
using System;
using System.Runtime.CompilerServices;
@ -19,9 +24,8 @@ namespace Cysharp.Threading.Tasks
// similar as IValueTaskSource
public interface IUniTaskSource
#if (!UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER) && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
: System.Threading.Tasks.Sources.IValueTaskSource
#pragma warning disable CS0108
#endif
{
UniTaskStatus GetStatus(short token);
@ -30,8 +34,7 @@ namespace Cysharp.Threading.Tasks
UniTaskStatus UnsafeGetStatus(); // only for debug use.
#if (!UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER) && !NETSTANDARD2_0
#pragma warning restore CS0108
#if SUPPORT_VALUETASK
System.Threading.Tasks.Sources.ValueTaskSourceStatus System.Threading.Tasks.Sources.IValueTaskSource.GetStatus(short token)
{
@ -53,13 +56,13 @@ namespace Cysharp.Threading.Tasks
}
public interface IUniTaskSource<out T> : IUniTaskSource
#if (!UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER) && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
, System.Threading.Tasks.Sources.IValueTaskSource<T>
#endif
{
new T GetResult(short token);
#if (!UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER) && !NETSTANDARD2_0
#if SUPPORT_VALUETASK
new public UniTaskStatus GetStatus(short token)
{

View File

@ -1,5 +1,10 @@
#if !UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER
#pragma warning disable 0649
#pragma warning disable 0649
#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
#if SUPPORT_VALUETASK
using System;
using System.Threading.Tasks;
@ -11,7 +16,7 @@ namespace Cysharp.Threading.Tasks
{
public static ValueTask AsValueTask(this in UniTask task)
{
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return new ValueTask(new UniTaskValueTaskSource(task), 0);
#else
return task;
@ -20,7 +25,7 @@ namespace Cysharp.Threading.Tasks
public static ValueTask<T> AsValueTask<T>(this in UniTask<T> task)
{
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return new ValueTask<T>(new UniTaskValueTaskSource<T>(task), 0);
#else
return task;
@ -37,7 +42,7 @@ namespace Cysharp.Threading.Tasks
await task;
}
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
class UniTaskValueTaskSource : IValueTaskSource
{

View File

@ -1,6 +1,10 @@
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CS0436
#if UNITASK_NETCORE || UNITY_2022_3_OR_NEWER
#define SUPPORT_VALUETASK
#endif
using Cysharp.Threading.Tasks.CompilerServices;
using System;
using System.Diagnostics;
@ -69,7 +73,7 @@ namespace Cysharp.Threading.Tasks
return new UniTask<bool>(new IsCanceledSource(source), token);
}
#if !UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER
#if SUPPORT_VALUETASK
public static implicit operator System.Threading.Tasks.ValueTask(in UniTask self)
{
@ -78,7 +82,7 @@ namespace Cysharp.Threading.Tasks
return default;
}
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return self.AsValueTask();
#else
return new System.Threading.Tasks.ValueTask(self.source, self.token);
@ -118,7 +122,7 @@ namespace Cysharp.Threading.Tasks
this.source.GetResult(this.token);
return CompletedTasks.AsyncUnit;
}
else if(this.source is IUniTaskSource<AsyncUnit> asyncUnitSource)
else if (this.source is IUniTaskSource<AsyncUnit> asyncUnitSource)
{
return new UniTask<AsyncUnit>(asyncUnitSource, this.token);
}
@ -440,7 +444,7 @@ namespace Cysharp.Threading.Tasks
return self.AsUniTask();
}
#if !UNITY_2018_3_OR_NEWER || UNITY_2022_3_OR_NEWER
#if SUPPORT_VALUETASK
public static implicit operator System.Threading.Tasks.ValueTask<T>(in UniTask<T> self)
{
@ -449,7 +453,7 @@ namespace Cysharp.Threading.Tasks
return new System.Threading.Tasks.ValueTask<T>(self.result);
}
#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return self.AsValueTask();
#else
return new System.Threading.Tasks.ValueTask<T>(self.source, self.token);