Skip to content

Commit

Permalink
Merge pull request #425 from timcassell/develop
Browse files Browse the repository at this point in the history
Merge v3.0.1 to master
  • Loading branch information
timcassell authored Apr 6, 2024
2 parents ed5a3eb + 8275d4c commit 26738bc
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 141 deletions.
2 changes: 0 additions & 2 deletions DeveloperNotes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
For each new release:

Before releasing, test the demo scene in Unity 5.5 to make sure it works (no need to run tests as the test runner didn't exist back then).

Update the version in `ProtoPromise.csproj`, `ProtoPromise.UnityHelpers/**.csproj`s, and `package.json`.


Expand Down
7 changes: 7 additions & 0 deletions Docs/Changelog/v3.0.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

## v3.0.1 - April 6, 2024

Fixes:

- `Fixed Promise<T>.IsValid` when it was completed synchronously.
11 changes: 2 additions & 9 deletions Package/Core/Promises/Promise.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,8 @@ public static implicit operator System.Threading.Tasks.ValueTask(in Promise rhs)
/// Gets whether this instance is valid to be awaited.
/// </summary>
public bool IsValid
{
[MethodImpl(Internal.InlineOption)]
get
{
// I would prefer to have a null ref only valid if the promise was created from Promise.Resolved, but it's more efficient to allow default values to be valid.
var r = _ref;
return r == null || r.GetIsValid(_id);
}
}
// I would prefer to have a null ref only valid if the promise was created from Promise.Resolved, but it's more efficient to allow default values to be valid.
=> _ref?.GetIsValid(_id) != false;

/// <summary>
/// Mark this as awaited and get a new <see cref="Promise"/> that inherits the state of this and can be awaited multiple times until <see cref="Forget"/> is called on it.
Expand Down
4 changes: 2 additions & 2 deletions Package/Core/Promises/PromiseStaticRace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ public static Promise<T> First<T, TEnumerator>(TEnumerator promises) where TEnum
/// Returns a <see cref="Promise{T}"/> of <see cref="ValueTuple{T1, T2}"/> that will resolve when the first of the promises has resolved with the index and result of that promise.
/// If any promise is rejected or canceled, the returned <see cref="Promise{T}"/> will immediately be canceled or rejected with the same reason.
/// </summary>
public static Promise<(int, T)> RaceWithIndex<T, TEnumerator>(TEnumerator promises) where TEnumerator : IEnumerator<Promise<T>>
public static Promise<(int winIndex, T result)> RaceWithIndex<T, TEnumerator>(TEnumerator promises) where TEnumerator : IEnumerator<Promise<T>>
{
ValidateArgument(promises, nameof(promises), 1);

Expand Down Expand Up @@ -780,7 +780,7 @@ public static Promise<T> First<T, TEnumerator>(TEnumerator promises) where TEnum
/// Returns a <see cref="Promise{T}"/> of <see cref="ValueTuple{T1, T2}"/> that will resolve when the first of the promises has resolved with the index and result of that promise.
/// If all promises are rejected or canceled, the returned <see cref="Promise{T}"/> will be canceled or rejected with the same reason as the last <see cref="Promise{T}"/> that is rejected or canceled.
/// </summary>
public static Promise<(int, T)> FirstWithIndex<T, TEnumerator>(TEnumerator promises) where TEnumerator : IEnumerator<Promise<T>>
public static Promise<(int winIndex, T result)> FirstWithIndex<T, TEnumerator>(TEnumerator promises) where TEnumerator : IEnumerator<Promise<T>>
{
ValidateArgument(promises, nameof(promises), 1);

Expand Down
2 changes: 1 addition & 1 deletion Package/Core/Promises/PromiseT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static implicit operator System.Threading.Tasks.ValueTask(in Promise<T> r
/// </summary>
public bool IsValid
// I would prefer to have a null ref only valid if the promise was created from Promise.Resolved, but it's more efficient to allow default values to be valid.
=> _ref?.GetIsValid(_id) == true;
=> _ref?.GetIsValid(_id) != false;

/// <summary>
/// Cast to <see cref="Promise"/>.
Expand Down
8 changes: 2 additions & 6 deletions Package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,9 @@ See the [C# Asynchronous Benchmarks Repo](https://github.com/timcassell/CSharpAs

## Latest Updates

### v3.0.0 - March 18, 2024
### v3.0.1 - April 6, 2024

- Added `UnityEngine.Awaitable` extensions to convert to `Promise`.
- Added API overloads accepting `ReadOnlySpan<T>` parameter.
- Improved performance and reduced memory.
- Removed support for runtimes older than .Net Standard 2.0.
- Removed deprecated and useless APIs.
- `Fixed Promise<T>.IsValid` when it was completed synchronously.

See [ChangeLog](https://github.com/timcassell/ProtoPromise/tree/master/Docs/Changelog) for the full changelog.

Expand Down
16 changes: 16 additions & 0 deletions Package/Tests/CoreTests/APIs/MiscellaneousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ public void Teardown()
TestHelper.s_expectedUncaughtRejectValue = null;
}

[Test]
public void PromiseIsValidBeforeAwaited_void()
{
var promise = Promise.Resolved();
Assert.IsTrue(promise.IsValid);
promise.Forget();
}

[Test]
public void PromiseIsValidBeforeAwaited_T()
{
var promise = Promise.Resolved(42);
Assert.IsTrue(promise.IsValid);
promise.Forget();
}

[Test]
public void PromiseIsInvalidAfterAwaited_void()
{
Expand Down
4 changes: 3 additions & 1 deletion Package/Tests/CoreTests/APIs/ParallelForEachAsyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,10 @@ public void ParallelForEachAsync_ExecutionContextFlowsToWorkerBodies(
{
await Promise.SwitchToForegroundAwait(forceAsync: true);
Assert.AreEqual(42, al.Value);
})
al.Value = 43;
}, context)
.WaitWithTimeoutWhileExecutingForegroundContext(TimeSpan.FromSeconds(Environment.ProcessorCount));
Assert.AreEqual(42, al.Value);
}

#if UNITY_2021_2_OR_NEWER || !UNITY_2018_3_OR_NEWER
Expand Down
8 changes: 6 additions & 2 deletions Package/Tests/CoreTests/APIs/ParallelForTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,10 @@ public void ParallelFor_ExecutionContextFlowsToWorkerBodies(
{
await Promise.SwitchToForegroundAwait(forceAsync: true);
Assert.AreEqual(42, al.Value);
})
al.Value = 43;
}, context)
.WaitWithTimeoutWhileExecutingForegroundContext(TimeSpan.FromSeconds(Environment.ProcessorCount));
Assert.AreEqual(42, al.Value);
}

private static IEnumerable<int> Iterate100()
Expand All @@ -574,8 +576,10 @@ public void ParallelForEach_ExecutionContextFlowsToWorkerBodies(
{
await Promise.SwitchToForegroundAwait(forceAsync: true);
Assert.AreEqual(42, al.Value);
})
al.Value = 43;
}, context)
.WaitWithTimeoutWhileExecutingForegroundContext(TimeSpan.FromSeconds(Environment.ProcessorCount));
Assert.AreEqual(42, al.Value);
}
}
#endif // !UNITY_WEBGL
Expand Down
2 changes: 1 addition & 1 deletion Package/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.timcassell.protopromise",
"version": "3.0.0",
"version": "3.0.1",
"displayName": "ProtoPromise",
"description": "Robust and efficient library for management of asynchronous operations.",
"changelogUrl": "https://github.com/timcassell/ProtoPromise/tree/master/Docs/Changelog",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!--We target .Net Standard 2.0 to support old Unity versions, and we also target .Net Standard 2.1 to use function pointers.-->
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<!--In case any IL2CPP issues need to be resolved like in the core library.-->
<DefineConstants>$(DefineConstants);ENABLE_IL2CPP</DefineConstants>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.1</TargetFrameworks>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<!-- The language version Unity supports in 2023.1. -->
<LangVersion>9</LangVersion>
<!--In case any IL2CPP issues need to be resolved like in the core library.-->
Expand Down
2 changes: 1 addition & 1 deletion ProtoPromise/ProtoPromise.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<Version>3.0.0</Version>
<Version>3.0.1</Version>
<!--Set true to help debug internal promise code (allows the debugger to step into the code and includes internal stacktraces).-->
<DeveloperMode>false</DeveloperMode>
</PropertyGroup>
Expand Down
19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/net35/ProtoPromise.targets

This file was deleted.

19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/net40/ProtoPromise.targets

This file was deleted.

19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/net45/ProtoPromise.targets

This file was deleted.

19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/net47/ProtoPromise.targets

This file was deleted.

19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/net5.0/ProtoPromise.targets

This file was deleted.

19 changes: 0 additions & 19 deletions ProtoPromise/nuget/targets/netcoreapp2.1/ProtoPromise.targets

This file was deleted.

0 comments on commit 26738bc

Please sign in to comment.