Skip to content

Commit fba6f9c

Browse files
committed
Merge branch 'release/0.9.8'
2 parents 2efe4b0 + aca8ccc commit fba6f9c

File tree

71 files changed

+3477
-2584
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3477
-2584
lines changed

.appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ dotnet_csproj:
3535
version: '$(GitVersion_MajorMinorPatch)'
3636
package_version: '$(GitVersion_NuGetVersionV2)'
3737
assembly_version: '$(GitVersion_AssemblySemVer)'
38-
file_version: '$(GitVersion_MajorMinorPatch).$(GitVersion_CommitsSinceVersionSource)'
38+
file_version: '$(GitVersion_AssemblySemVer)'
3939
informational_version: '$(GitVersion_InformationalVersion)'
4040

4141
deploy:

CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/).
55

6+
-----------------------
7+
## [0.9.8] - 2018.11.09
8+
9+
### Added
10+
- `AsyncResult` is now Task-like type and can be used as `async` method result value (requires C# 7.2).
11+
- Added new `AsyncResult.FromAction` overloads.
12+
- Added new `SynchronizationContext` extension methods (`PostAsync`, `InvokeAsync` etc).
13+
- Added extension methods for `Socket`, `WebRequest`, `Stream` BCL classes.
14+
15+
### Changed
16+
- Moved BCL extension methods to namespace `UnityFx.Async.Extensions` (previously they were in namespace `UnityFx.Async`).
17+
18+
### Fixed
19+
- Fixed `AsyncResult` completion callbacks to be called event if `OnCompleted` throws.
20+
- Fixed exception not been set for `AsyncResult.FaultedOperation` and `AsyncResult.CanceledOperation`.
21+
- Disabled `MovieTexture` helpers for iOS/Android (as it is not supported on mobiles).
22+
23+
### Removed
24+
- Removed `AsyncResultQueue`.
25+
- Removed `AsyncLazy`.
26+
627
-----------------------
728
## [0.9.7] - 2018.09.27
829

README.md

+18-16
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ Channel | UnityFx.Async |
55
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)
66
NuGet | [![NuGet](https://img.shields.io/nuget/v/UnityFx.Async.svg)](https://www.nuget.org/packages/UnityFx.Async)
77
Github | [![GitHub release](https://img.shields.io/github/release/Arvtesh/UnityFx.Async.svg?logo=github)](https://github.com/Arvtesh/UnityFx.Async/releases)
8-
Unity Asset Store | [![Asynchronous operations for Unity](https://img.shields.io/badge/tools-v0.9.7-green.svg)](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696)
8+
Unity Asset Store | [![Asynchronous operations for Unity](https://img.shields.io/badge/tools-v0.9.8-green.svg)](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696)
99

10-
**Required Unity 5.4 or higher.**
10+
**Requires Unity 5.4 or higher.**
1111

1212
**If you enjoy using the library - please, [rate and review](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696) it on the Asset Store!**
1313

14+
**Please ask any questions and leave feedback at the [Unity forums](https://forum.unity.com/threads/asynchronous-operations-for-unity-free.522989/).**
15+
1416
## Synopsis
1517

1618
*UnityFx.Async* introduces effective and portable asynchronous operations that can be used very much like [Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) in .NET or [Promises](https://developers.google.com/web/fundamentals/primers/promises) in JS. [AsyncResult](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.AsyncResult.html) class is an implementation of a generic asynchronous operation (aka `promise` or `future`). In many aspects it mimics [Task](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) (for example, it can be used with `async`/`await` operators, supports continuations and synchronization context capturing) while maintaining Unity/net35 compatibility. It is a great foundation toolset for any Unity project.
@@ -27,15 +29,17 @@ The table below summarizes differences berween *UnityFx.Async* and other popular
2729
| Stat | UnityFx.Async | [C-Sharp-Promise](https://github.com/Real-Serious-Games/C-Sharp-Promise) | [TPL](https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl) |
2830
| :--- | :---: | :---: | :---: |
2931
| Thread-safe | ✔️ | - | ✔️ |
30-
| Can capture synchronization context | ✔️ | - | ✔️ |
3132
| .NET 3.5 compilance | ✔️ | ✔️ | -️️ |
33+
| Supports [SynchronizationContext](https://docs.microsoft.com/en-us/dotnet/api/system.threading.synchronizationcontext) capturing | ✔️ | - | ✔️ |
3234
| Supports continuations | ✔️ | ✔️ | ✔️ |
3335
| Supports Unity coroutines | ️️✔️ | - | - |
34-
| Supports `async` / `await` | ✔️ | - | ✔️ |
35-
| Supports `promise`-like continuations | ✔️ | ✔️ | - |
36+
| Supports [async / await](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/index) | ✔️ | - | ✔️ |
37+
| Supports [promise](https://www.promisejs.org/)-like continuations | ✔️ | ✔️ | - |
3638
| Supports cancellation | ✔️ | -️ | ✔️ |
3739
| Supports progress reporting | ✔️ | ✔️ | ✔️ |
3840
| Supports child operations | - | - | ✔️ |
41+
| Supports [Task-like types](https://github.com/dotnet/roslyn/blob/master/docs/features/task-types.md) (requires C# 7.2) | ✔️ | - | ✔️ |
42+
| Supports [ExecutionContext](https://docs.microsoft.com/en-us/dotnet/api/system.threading.executioncontext) flow | - | - | ✔️ |
3943
| Minimum operation data size for 32-bit systems (in bytes) | 32+ | 36+ | 40+ |
4044
| Minimum number of allocations per continuation | ~1 | 5+ | 2+ |
4145

@@ -55,7 +59,7 @@ git submodule -q update --init
5559
The binaries are available as a [NuGet package](https://www.nuget.org/packages/UnityFx.Async). See [here](http://docs.nuget.org/docs/start-here/using-the-package-manager-console) for instructions on installing a package via nuget. One can also download them directly from [Github releases](https://github.com/Arvtesh/UnityFx.Async/releases). Unity3d users can import corresponding [Unity Asset Store package](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696) using the editor.
5660

5761
### Unity dependencies
58-
The library core (`UnityFx.Async.dll`) does not depend on Unity and can be used in any .NET projects (via assembly or [NuGet](https://www.nuget.org/packages/UnityFx.Async) reference). All Unity-specific stuff depends on the core and is included in [Unity Asset Store package](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696).
62+
The library core (`UnityFx.Async.dll`) does not depend on Unity and can be used in any .NET project (via assembly or [NuGet](https://www.nuget.org/packages/UnityFx.Async) reference). All Unity-specific stuff depends on the core and is included in [Asset Store package](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696).
5963

6064
## Understanding the concepts
6165
The topics below are just a quick summary of problems and the proposed solutions. For more details on the topic please see useful links at the end of this document.
@@ -439,7 +443,7 @@ Most common way of creating own asynchronous operation is instantiating `AsyncCo
439443
* `AsyncResult`: an asynchronous operation without a result value.
440444
* `AsyncResult<TResult>`: an asynchronous operation with a result value.
441445

442-
The sample code below demostrates creating a delay operation (in fact library provides one, this is just a simplified example):
446+
The sample code below demostrates creating a delay operation (in fact the library provides one, this is just a simplified example):
443447
```csharp
444448
public class TimerDelayResult : AsyncResult
445449
{
@@ -479,10 +483,9 @@ public class TimerDelayResult : AsyncResult
479483
```
480484

481485
### Unity3d helpers
482-
The library consists of 3 major parts:
486+
As stated abovethe library include 2 main parts:
483487
* Core tools (defined in `UnityFx.Async.dll` assembly, do not depend on Unity3d);
484-
* Unity3d-specific tools (defined as a collection of C# scripts located in `Assets/Plugins/UnityFx.Async` if installed as an Asset Store package, require Unity3d to compile/execute).
485-
* Unity3d samples (defined as a collection of C# scripts located in `Assets/UnityFx.Async` if installed as an Asset Store package, require Unity3d to compile/execute).
488+
* Unity3d-specific tools (defined as a collection of C# scripts if installed as an Asset Store package, require Unity3d to compile/execute).
486489

487490
Everything described before (unless specified otherwise) does not require Unity and can be used in any application. The Unity-specific stuff is located in 3 classes:
488491
* `AsyncUtility`. Defines helper methods for accessing main thread in Unity, running coroutines without actually using a `MonoBehaviour` and waiting for native Unity asynchronous operations outside of coroutines.
@@ -492,11 +495,11 @@ Everything described before (unless specified otherwise) does not require Unity
492495
For example, one can throw a few lines of code to be executed on a main thread using:
493496
```csharp
494497
// Sends a delegate to the main thread and blocks calling thread until it is executed.
495-
AsyncUtility.SendToMainThread(args => Debug.Log("On the main thread."), null);
498+
AsyncUtility.SendToMainThread(() => Debug.Log("On the main thread."));
496499
// Posts a delegate to the main thread and returns immediately. Returns an asynchronous operation that can be used to track the delegate execution.
497-
AsyncUtility.PostToMainThread(args => Debug.Log("On the main thread."), null);
500+
AsyncUtility.PostToMainThread(() => Debug.Log("On the main thread."));
498501
// If calling thread is the main thread executes the delegate synchronously, otherwise posts it to the main thread. Returns an asynchronous operation that can be used to track the delegate execution.
499-
AsyncUtility.InvokeOnMainThread(args => Debug.Log("On the main thread."), null);
502+
AsyncUtility.InvokeOnMainThread(() => Debug.Log("On the main thread."));
500503
```
501504

502505
## Comparison to .NET Tasks
@@ -516,15 +519,14 @@ TPL | UnityFx.Async | Notes
516519
&#45; | [IAsyncCancellable](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.IAsyncCancellable.html) | A cancellable operation.
517520
&#45; | [IAsyncContinuation](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.IAsyncContinuation.html) | A generic non-delegate operation continuation.
518521
&#45; | [IAsyncUpdatable](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.IAsyncUpdatable.html), [IAsyncUpdateSource](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.IAsyncUpdateSource.html) | A consumer and provider sides for frame update notifications.
519-
&#45; | [AsyncResultQueue&lt;T&gt;](https://arvtesh.github.io/UnityFx.Async/api/netstandard2.0/UnityFx.Async.AsyncResultQueue-1.html) | A FIFO queue of asynchronous operations executed sequentially.
520522

521523
Please note that the library is NOT a replacement for [Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) or [TPL](https://docs.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl). As a general rule it is recommended to use [Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) and only switch to *UnityFx.Async* if one of the following applies:
522524
- .NET 3.5/[Unity3d](https://unity3d.com) compatibility is required.
523525
- Memory usage is a concern ([Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) tend to do quite a lot of allocations).
524526
- An extendable [IAsyncResult](https://docs.microsoft.com/en-us/dotnet/api/system.iasyncresult) implementation is needed.
525527

526528
## Motivation
527-
The project was initially created to help author with his [Unity3d](https://unity3d.com) projects. Unity's [AsyncOperation](https://docs.unity3d.com/ScriptReference/AsyncOperation.html) and similar can only be used in coroutines, cannot be extended and mostly do not return result or error information, .NET 3.5 does not provide much help either and even with .NET 4.6 support compatibility requirements often do not allow using [Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task). When I caught myself writing the same asynchronous operation wrappers in each project I decided to share my experience to the best of human kind.
529+
The project was initially created to help author with his [Unity3d](https://unity3d.com) projects. Unity's [AsyncOperation](https://docs.unity3d.com/ScriptReference/AsyncOperation.html) and similar can only be used in coroutines, cannot be extended and mostly do not return result or error information, .NET 3.5 does not provide much help either and even with .NET 4.6 support compatibility requirements often do not allow using [Tasks](https://docs.microsoft.com/en-us/dotnet/api/system.threading.tasks.task) (and they are quite expensive). When I caught myself writing the same asynchronous operation wrappers in each project I decided to share my experience to the best of human kind.
528530

529531
## Documentation
530532
Please see the links below for extended information on the product:
@@ -554,7 +556,7 @@ The project uses [SemVer](https://semver.org/) versioning pattern. For the versi
554556
Please see the [![license](https://img.shields.io/github/license/Arvtesh/UnityFx.Async.svg)](LICENSE.md) for details.
555557

556558
## Acknowledgments
557-
Working on this project is a great experience. Please see below list of sources of my inspiration (in no particular order):
559+
Working on this project is a great experience. Please see below a list of my inspiration sources (in no particular order):
558560
* [.NET reference source](https://referencesource.microsoft.com/mscorlib/System/threading/Tasks/Task.cs.html). A great source of knowledge and good programming practices.
559561
* [C-Sharp-Promise](https://github.com/Real-Serious-Games/C-Sharp-Promise). Another great C# promise library with excellent documentation.
560562
* [UniRx](https://github.com/neuecc/UniRx). A deeply reworked [Rx.NET](https://github.com/Reactive-Extensions/Rx.NET) port to Unity.

src/UnityFx.Async.AssetStore/Assets/Plugins/UnityFx.Async/README.txt

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
SUMMARY
2-
The package provides lightweight Task-like asynchronous operations (promises) for Unity3d.
3-
4-
PUBLISHER INFORMATION
5-
https://www.linkedin.com/in/alexander-bogarsukov-93b9682/
2+
Lightweight Task-like asynchronous operations (promises) for Unity3d.
63

74
LICENSE
85
https://github.com/Arvtesh/UnityFx.Async/blob/master/LICENSE.md

src/UnityFx.Async.AssetStore/Assets/Plugins/UnityFx.Async/Scripts/AsyncUtility.cs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using System.Threading;
1212
using UnityEngine;
1313
using UnityEngine.Networking;
14+
using UnityFx.Async.Extensions;
1415

1516
namespace UnityFx.Async
1617
{

src/UnityFx.Async.AssetStore/Assets/Plugins/UnityFx.Async/Scripts/AsyncWww.cs

+12-9
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public static IAsyncOperation<Texture2D> GetTexture(string url, bool nonReadable
204204
return result;
205205
}
206206

207-
#if !UNITY_2018_2_OR_NEWER
207+
#if !UNITY_2018_2_OR_NEWER && !UNITY_IOS && !UNITY_ANDROID
208208

209209
/// <summary>
210210
/// Creates an asyncronous operation optimized for downloading a <see cref="MovieTexture"/> via HTTP GET.
@@ -254,7 +254,7 @@ public static T GetResult<T>(UnityWebRequest request) where T : class
254254
{
255255
return ((DownloadHandlerAudioClip)request.downloadHandler).audioClip as T;
256256
}
257-
#if !UNITY_5 && !UNITY_2018_2_OR_NEWER
257+
#if !UNITY_5 && !UNITY_2018_2_OR_NEWER && !UNITY_IOS && !UNITY_ANDROID
258258
else if (request.downloadHandler is DownloadHandlerMovieTexture)
259259
{
260260
return ((DownloadHandlerMovieTexture)request.downloadHandler).movieTexture as T;
@@ -298,21 +298,24 @@ public static T GetResult<T>(WWW request) where T : class
298298
{
299299
return request.GetAudioClip() as T;
300300
}
301-
#if !UNITY_2018_2_OR_NEWER
302-
else if (typeof(T) == typeof(MovieTexture))
303-
{
304-
return request.GetMovieTexture() as T;
305-
}
306-
#endif
307301
#else
308302
else if (typeof(T) == typeof(AudioClip))
309303
{
310304
return request.audioClip as T;
311305
}
306+
#endif
307+
#if !UNITY_2018_2_OR_NEWER && !UNITY_IOS && !UNITY_ANDROID
308+
#if UNITY_5_6_OR_NEWER
309+
else if (typeof(T) == typeof(MovieTexture))
310+
{
311+
return request.GetMovieTexture() as T;
312+
}
313+
#else
312314
else if (typeof(T) == typeof(MovieTexture))
313315
{
314316
return request.movie as T;
315317
}
318+
#endif
316319
#endif
317320
else if (typeof(T) == typeof(byte[]))
318321
{
@@ -327,5 +330,5 @@ public static T GetResult<T>(WWW request) where T : class
327330
}
328331

329332
#endif
333+
}
330334
}
331-
}

src/UnityFx.Async.AssetStore/Assets/Plugins/UnityFx.Async/Scripts/UnityExtensions.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,13 @@ public AsyncOperationAwaiter(AsyncOperation op)
120120
/// Gets a value indicating whether the underlying operation is completed.
121121
/// </summary>
122122
/// <value>The operation completion flag.</value>
123-
public bool IsCompleted => _op.isDone;
123+
public bool IsCompleted
124+
{
125+
get
126+
{
127+
return _op.isDone;
128+
}
129+
}
124130

125131
/// <summary>
126132
/// Returns the source result value.
@@ -216,7 +222,13 @@ public UnityWebRequestAwaiter(UnityWebRequest op)
216222
/// Gets a value indicating whether the underlying operation is completed.
217223
/// </summary>
218224
/// <value>The operation completion flag.</value>
219-
public bool IsCompleted => _op.isDone;
225+
public bool IsCompleted
226+
{
227+
get
228+
{
229+
return _op.isDone;
230+
}
231+
}
220232

221233
/// <summary>
222234
/// Returns the source result value.
@@ -314,7 +326,13 @@ public WwwAwaiter(WWW op)
314326
/// Gets a value indicating whether the underlying operation is completed.
315327
/// </summary>
316328
/// <value>The operation completion flag.</value>
317-
public bool IsCompleted => _op.isDone;
329+
public bool IsCompleted
330+
{
331+
get
332+
{
333+
return _op.isDone;
334+
}
335+
}
318336

319337
/// <summary>
320338
/// Returns the source result value.

src/UnityFx.Async.AssetStore/UnityFx.Async.AssetStore.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<IsPackable>false</IsPackable>
1818
<GenerateDocumentationFile>true</GenerateDocumentationFile>
1919
<CodeAnalysisRuleSet>../CodingConventions/Cs/CsharpRules.ruleset</CodeAnalysisRuleSet>
20-
<LangVersion>6</LangVersion>
20+
<LangVersion>4</LangVersion>
2121
</PropertyGroup>
2222

2323
<PropertyGroup Condition="'$(TargetFramework)' == 'net46'">

src/UnityFx.Async.Tests/Tests/AsyncResultQueueTests.cs

-73
This file was deleted.

0 commit comments

Comments
 (0)