Skip to content

Commit

Permalink
simplify UNITASK define
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jan 25, 2024
1 parent 0ef6c59 commit 08184af
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 50 deletions.
69 changes: 35 additions & 34 deletions src/UniTask.NetCore/UniTask.NetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<AssemblyName>UniTask</AssemblyName>
<LangVersion>8.0</LangVersion>
<RootNamespace>Cysharp.Threading.Tasks</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0;netstandard2.1;netstandard2.0</TargetFrameworks>
<AssemblyName>UniTask</AssemblyName>
<LangVersion>8.0</LangVersion>
<RootNamespace>Cysharp.Threading.Tasks</RootNamespace>
<DefineConstants>UNITASK_NETCORE</DefineConstants>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);CS1591</NoWarn>

<!-- NuGet Packaging -->
<Id>UniTask</Id>
<PackageVersion>$(Version)</PackageVersion>
<Company>Cysharp</Company>
<Authors>Cysharp</Authors>
<Copyright>© Cysharp, Inc.</Copyright>
<PackageTags>task;async</PackageTags>
<Description>Provides an efficient async/await integration to Unity and .NET Core.</Description>
<PackageProjectUrl>https://github.com/Cysharp/UniTask</PackageProjectUrl>
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>Icon.png</PackageIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>opensource.snk</AssemblyOriginatorKeyFile>
<IsPackable>true</IsPackable>
</PropertyGroup>
<!-- NuGet Packaging -->
<Id>UniTask</Id>
<PackageVersion>$(Version)</PackageVersion>
<Company>Cysharp</Company>
<Authors>Cysharp</Authors>
<Copyright>© Cysharp, Inc.</Copyright>
<PackageTags>task;async</PackageTags>
<Description>Provides an efficient async/await integration to Unity and .NET Core.</Description>
<PackageProjectUrl>https://github.com/Cysharp/UniTask</PackageProjectUrl>
<RepositoryUrl>$(PackageProjectUrl)</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageIcon>Icon.png</PackageIcon>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>opensource.snk</AssemblyOriginatorKeyFile>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup>
<None Include="Icon.png" Pack="true" PackagePath="/" />
</ItemGroup>
<ItemGroup>
<None Include="Icon.png" Pack="true" PackagePath="/" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\UniTask\Assets\Plugins\UniTask\Runtime\**\*.cs" Exclude="&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Editor\*.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Triggers\*.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Linq\UnityExtensions\*.cs;&#xD;&#xA; &#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityEqualityComparer.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\DiagnosticsExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\PlayerLoopRunner.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\ContinuationQueue.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityWebRequestExtensions.cs;&#xD;&#xA; &#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTaskSynchronizationContext.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\CancellationTokenSourceExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\TimeoutController.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopHelper.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopTimer.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Delay.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Run.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Bridge.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.WaitUntil.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.*;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UnityBindingExtensions.cs;&#xD;&#xA;" />
<Compile Remove="..\UniTask\Assets\Plugins\UniTask\Runtime\_InternalVisibleTo.cs" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\UniTask\Assets\Plugins\UniTask\Runtime\**\*.cs" Exclude="&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Editor\*.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Triggers\*.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Linq\UnityExtensions\*.cs;&#xD;&#xA; &#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityEqualityComparer.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\DiagnosticsExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\PlayerLoopRunner.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\ContinuationQueue.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\Internal\UnityWebRequestExtensions.cs;&#xD;&#xA; &#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTaskSynchronizationContext.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\CancellationTokenSourceExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\EnumeratorAsyncExtensions.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\TimeoutController.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopHelper.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\PlayerLoopTimer.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Delay.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Run.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.Bridge.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UniTask.WaitUntil.cs;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UnityAsyncExtensions.*;&#xD;&#xA;..\UniTask\Assets\Plugins\UniTask\Runtime\UnityBindingExtensions.cs;&#xD;&#xA;" />
<Compile Remove="..\UniTask\Assets\Plugins\UniTask\Runtime\_InternalVisibleTo.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.4" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions src/UniTask.NetCoreTests/Linq/Merge.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS1998

using System;
using System.Threading;
using System.Threading.Tasks;
Expand Down
2 changes: 2 additions & 0 deletions src/UniTask.NetCoreTests/TaskExtensionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma warning disable CS1998

using System;
using System.Threading.Tasks;
using Cysharp.Threading.Tasks;
Expand Down
15 changes: 9 additions & 6 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/IUniTaskSource.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,9 +24,8 @@ public enum UniTaskStatus

// 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);
Expand All @@ -30,8 +34,7 @@ public interface IUniTaskSource

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)
{
Expand All @@ -53,13 +56,13 @@ void System.Threading.Tasks.Sources.IValueTaskSource.OnCompleted(Action<object>
}

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)
{
Expand Down
15 changes: 10 additions & 5 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.AsValueTask.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,7 +16,7 @@ public static class UniTaskValueTaskExtensions
{
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;
Expand All @@ -20,7 +25,7 @@ public static ValueTask AsValueTask(this in UniTask task)

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;
Expand All @@ -37,7 +42,7 @@ public static async UniTask AsUniTask(this ValueTask task)
await task;
}

#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)

class UniTaskValueTaskSource : IValueTaskSource
{
Expand Down
14 changes: 9 additions & 5 deletions src/UniTask/Assets/Plugins/UniTask/Runtime/UniTask.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -69,7 +73,7 @@ public UniTask<bool> SuppressCancellationThrow()
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)
{
Expand All @@ -78,7 +82,7 @@ public static implicit operator System.Threading.Tasks.ValueTask(in UniTask self
return default;
}

#if NETSTANDARD2_0
#if (UNITASK_NETCORE && NETSTANDARD2_0)
return self.AsValueTask();
#else
return new System.Threading.Tasks.ValueTask(self.source, self.token);
Expand Down Expand Up @@ -118,7 +122,7 @@ public UniTask<AsyncUnit> AsAsyncUnitUniTask()
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);
}
Expand Down Expand Up @@ -440,7 +444,7 @@ public static implicit operator UniTask(UniTask<T> self)
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)
{
Expand All @@ -449,7 +453,7 @@ public static implicit operator System.Threading.Tasks.ValueTask<T>(in UniTask<T
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);
Expand Down

0 comments on commit 08184af

Please sign in to comment.