Skip to content

Commit

Permalink
Merge branch 'release/0.8.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvtesh committed Mar 28, 2018
2 parents 49af959 + de6d7b0 commit d16b503
Show file tree
Hide file tree
Showing 14 changed files with 573 additions and 152 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/); this proj
-----------------------
## [Unreleased]

-----------------------
## [0.8.2] - 2018-03-28

### Added
- New `AsyncResult` constructors added.
- New overloads for `AsyncResult.FromResult`, `AsyncResult.FromCanceled` and `AsyncResult.FromException` methods added.

### Changed
- Made optimizations to `ToTask` extensions implementation for cases when target operation is completed.
- Marked all assembly classes CLS-compilant.

### Fixed
- `ToTask` extensions now throw inner exception instead of the `AggregateException` in case of an error.
- Fixed `AsyncResult.Delay` throwing exception when infinite delay (-1) specified.

-----------------------
## [0.8.1] - 2018-03-19

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Channel | UnityFx.Async |
AppVeyor | [![Build status](https://ci.appveyor.com/api/projects/status/hfmq9vow53al7tpd/branch/master?svg=true)](https://ci.appveyor.com/project/Arvtesh/unityfx-async/branch/master) [![AppVeyor tests](https://img.shields.io/appveyor/tests/Arvtesh/unityFx-async.svg)](https://ci.appveyor.com/project/Arvtesh/unityfx-async/build/tests)
NuGet | [![NuGet](https://img.shields.io/nuget/v/UnityFx.Async.svg)](https://www.nuget.org/packages/UnityFx.Async) [![NuGet](https://img.shields.io/nuget/vpre/UnityFx.Async.svg)](https://www.nuget.org/packages/UnityFx.Async)
Github | [![GitHub release](https://img.shields.io/github/release/Arvtesh/UnityFx.Async.svg?logo=github)](https://github.com/Arvtesh/UnityFx.Async/releases)
Unity Asset Store | [![Asynchronous operations for Unity](https://img.shields.io/badge/tools-v0.8.1-green.svg)](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696)
Unity Asset Store | [![Asynchronous operations for Unity](https://img.shields.io/badge/tools-v0.8.2-green.svg)](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696)

## Synopsis

Expand Down Expand Up @@ -157,6 +157,7 @@ The project was initially created to help author with his [Unity3d](https://unit

## Documentation
Please see the links below for extended information on the product:
- [Unity forums](https://forum.unity.com/threads/asynchronous-operations-for-unity-free.522989/).
- [Documentation](https://arvtesh.github.io/UnityFx.Async/articles/intro.html).
- [API Reference](https://arvtesh.github.io/UnityFx.Async/api/index.html).
- [CHANGELOG](CHANGELOG.md).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ USEFUL LINKS
Github project: https://github.com/Arvtesh/UnityFx.Async
NuGet package: https://www.nuget.org/packages/UnityFx.Async
Unity Asset Store: https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696
Unity Forums: https://forum.unity.com/threads/asynchronous-operations-for-unity-free.522989/
40 changes: 40 additions & 0 deletions src/UnityFx.Async.Tests/Tests/AsyncExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,45 @@ public async Task ContinueWith_CompletesWhenBothOperationsComplete()
}

#endregion

#region ToTask

[Fact]
public async Task ToTask_CompletesWhenSourceCompletes()
{
// Arrange
var op = AsyncResult.Delay(1);
var task = op.ToTask();

// Act
await task;

// Assert
Assert.True(op.IsCompleted);
}

[Fact]
public async Task ToTask_FailsWhenSourceFails()
{
// Arrange
var op = AsyncResult.Delay(1).ContinueWith(result => AsyncResult.FromException(new Exception()));
var task = op.ToTask();

// Act/Assert
await Assert.ThrowsAsync<Exception>(() => task);
}

[Fact]
public async Task ToTask_FailsWhenSourceIsCanceled()
{
// Arrange
var op = AsyncResult.Delay(1).ContinueWith(result => AsyncResult.FromCanceled());
var task = op.ToTask();

// Act/Assert
await Assert.ThrowsAsync<TaskCanceledException>(() => task);
}

#endregion
}
}
29 changes: 29 additions & 0 deletions src/UnityFx.Async.Tests/Tests/AsyncResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,35 @@ IAsyncOperation OpFactory()
Assert.Equal(2, counter);
}

[Fact]
public async Task WhenAll_CompletesWhenAllOperationsCompleted()
{
// Arrange
var op1 = AsyncResult.Delay(1);
var op2 = AsyncResult.Delay(2);

// Act
await AsyncResult.WhenAll(op1, op2);

// Assert
AssertCompleted(op1);
AssertCompleted(op2);
}

[Fact]
public async Task WhenAny_CompletesWhenAnyOperationCompletes()
{
// Arrange
var op1 = AsyncResult.Delay(1);
var op2 = AsyncResult.Delay(Timeout.Infinite);

// Act
await AsyncResult.WhenAny(op1, op2);

// Assert
AssertCompleted(op1);
}

#endregion

#region interface
Expand Down
74 changes: 68 additions & 6 deletions src/UnityFx.Async/Api/Core/AsyncCompletionSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public AsyncCompletionSource()
/// </summary>
/// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
public AsyncCompletionSource(object asyncState)
: base(null, asyncState)
: base(default(AsyncCallback), asyncState)
{
}

Expand Down Expand Up @@ -55,7 +55,7 @@ public AsyncCompletionSource(AsyncOperationStatus status)
/// <param name="status">Initial value of the <see cref="AsyncResult.Status"/> property.</param>
/// <param name="asyncState">User-defined data returned by <see cref="IAsyncResult.AsyncState"/>.</param>
public AsyncCompletionSource(AsyncOperationStatus status, object asyncState)
: base(status, null, asyncState)
: base(status, asyncState)
{
}

Expand Down Expand Up @@ -118,6 +118,21 @@ public void SetRunning()
/// <seealso cref="TrySetScheduled"/>
public new bool TrySetRunning() => base.TrySetRunning();

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Canceled"/> state.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if the transition fails.</exception>
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetCanceled(bool)"/>
/// <seealso cref="TrySetCanceled()"/>
public void SetCanceled()
{
if (!base.TrySetCanceled(false))
{
throw new InvalidOperationException();
}
}

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Canceled"/> state.
/// </summary>
Expand All @@ -126,7 +141,7 @@ public void SetRunning()
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetCanceled(bool)"/>
/// <seealso cref="TrySetCanceled()"/>
public void SetCanceled(bool completedSynchronously = false)
public void SetCanceled(bool completedSynchronously)
{
if (!base.TrySetCanceled(completedSynchronously))
{
Expand All @@ -144,6 +159,22 @@ public void SetCanceled(bool completedSynchronously = false)
/// <seealso cref="TrySetCanceled()"/>
public new bool TrySetCanceled(bool completedSynchronously) => base.TrySetCanceled(completedSynchronously);

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Faulted"/> state.
/// </summary>
/// <param name="exception">An exception that caused the operation to end prematurely.</param>
/// <exception cref="InvalidOperationException">Thrown if the transition fails.</exception>
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetException(Exception, bool)"/>
/// <seealso cref="TrySetException(Exception)"/>
public void SetException(Exception exception)
{
if (!base.TrySetException(exception, false))
{
throw new InvalidOperationException();
}
}

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Faulted"/> state.
/// </summary>
Expand All @@ -153,7 +184,7 @@ public void SetCanceled(bool completedSynchronously = false)
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetException(Exception, bool)"/>
/// <seealso cref="TrySetException(Exception)"/>
public void SetException(Exception exception, bool completedSynchronously = false)
public void SetException(Exception exception, bool completedSynchronously)
{
if (!base.TrySetException(exception, completedSynchronously))
{
Expand All @@ -172,6 +203,22 @@ public void SetException(Exception exception, bool completedSynchronously = fals
/// <seealso cref="TrySetException(Exception)"/>
public new bool TrySetException(Exception exception, bool completedSynchronously) => base.TrySetException(exception, completedSynchronously);

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Faulted"/> state.
/// </summary>
/// <param name="exceptions">Exceptions that caused the operation to end prematurely.</param>
/// <exception cref="InvalidOperationException">Thrown if the transition fails.</exception>
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetExceptions(IEnumerable{Exception}, bool)"/>
/// <seealso cref="TrySetExceptions(IEnumerable{Exception})"/>
public void SetExceptions(IEnumerable<Exception> exceptions)
{
if (!base.TrySetExceptions(exceptions, false))
{
throw new InvalidOperationException();
}
}

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.Faulted"/> state.
/// </summary>
Expand All @@ -181,7 +228,7 @@ public void SetException(Exception exception, bool completedSynchronously = fals
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetExceptions(IEnumerable{Exception}, bool)"/>
/// <seealso cref="TrySetExceptions(IEnumerable{Exception})"/>
public void SetExceptions(IEnumerable<Exception> exceptions, bool completedSynchronously = false)
public void SetExceptions(IEnumerable<Exception> exceptions, bool completedSynchronously)
{
if (!base.TrySetExceptions(exceptions, completedSynchronously))
{
Expand All @@ -200,6 +247,21 @@ public void SetExceptions(IEnumerable<Exception> exceptions, bool completedSynch
/// <seealso cref="TrySetExceptions(IEnumerable{Exception})"/>
public new bool TrySetExceptions(IEnumerable<Exception> exceptions, bool completedSynchronously) => base.TrySetExceptions(exceptions, completedSynchronously);

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.RanToCompletion"/> state.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown if the transition fails.</exception>
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetCompleted(bool)"/>
/// <seealso cref="TrySetCompleted()"/>
public void SetCompleted()
{
if (!base.TrySetCompleted(false))
{
throw new InvalidOperationException();
}
}

/// <summary>
/// Transitions the operation into the <see cref="AsyncOperationStatus.RanToCompletion"/> state.
/// </summary>
Expand All @@ -208,7 +270,7 @@ public void SetExceptions(IEnumerable<Exception> exceptions, bool completedSynch
/// <exception cref="ObjectDisposedException">Thrown is the operation is disposed.</exception>
/// <seealso cref="TrySetCompleted(bool)"/>
/// <seealso cref="TrySetCompleted()"/>
public void SetCompleted(bool completedSynchronously = false)
public void SetCompleted(bool completedSynchronously)
{
if (!base.TrySetCompleted(completedSynchronously))
{
Expand Down
Loading

0 comments on commit d16b503

Please sign in to comment.