Skip to content

Commit ea684af

Browse files
committed
Merge branch 'release/0.9.4'
2 parents 3bd906b + e93baeb commit ea684af

29 files changed

+1423
-920
lines changed

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.4] - 2018.07.10
8+
9+
### Added
10+
- Added assembly definition file for Unity 2017.3+.
11+
- Added `AsyncResult.FaultedOperation` helper.
12+
- Added `AsyncUtility.IsMainThread` method.
13+
- Added `AsyncUtility.GetAssetBundle`, `AsyncUtility.GetTexture`, `AsyncUtility.AudioClip` and `AsyncUtility.GetMovieTexture` helper methods.
14+
- Added `AssetBundleCreateRequest` wrapper operation.
15+
- Added `ThrowIfNonSuccess` extension for `IAsyncOperation`.
16+
- Added `ToEnum` extension for `IAsyncResult` that converts an asynchronous operation (`Task`, `AsyncResult` etc) to enumerator.
17+
- Added `IAsyncSchedulable` interface - an abstraction of a schedulable entity.
18+
- Added `AsyncLazy` helper for initialization operations.
19+
20+
### Fixed
21+
- Fixed compile warnings for some older Unity versions.
22+
- Fixed error handling for Unity operation wrappers.
23+
24+
### Removed
25+
- Removed `AggregateException` class for net35.
26+
627
-----------------------
728
## [0.9.3] - 2018.06.09
829

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ NuGet | [![NuGet](https://img.shields.io/nuget/v/UnityFx.Async.svg)](https://www
77
Github | [![GitHub release](https://img.shields.io/github/release/Arvtesh/UnityFx.Async.svg?logo=github)](https://github.com/Arvtesh/UnityFx.Async/releases)
88
Unity Asset Store | [![Asynchronous operations for Unity](https://img.shields.io/badge/tools-v0.9.3-green.svg)](https://assetstore.unity.com/packages/tools/asynchronous-operations-for-unity-96696)
99

10+
**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!**
11+
1012
## Synopsis
1113

1214
*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.
@@ -331,12 +333,12 @@ DownloadTextAsync("http://www.google.com")
331333
.Then(text => ExtractFirstParagraph(text))
332334
.WithCancellation(cancellationToken);
333335
```
334-
If the [token](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken) passed to `WithCancellation()` is cancelled the target operation is cancelled as well (and that means cancelling all chained operations) as soon as possible. Cancellation might not be instant (depends on specific operation implementation). Also, please note that not all operations might support cancellation; in this case `Cancel()` will throw `NotSupportedException`.
336+
If the [token](https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken) passed to `WithCancellation()` is cancelled, the target operation is cancelled as well (and that means cancelling all chained operations) as soon as possible. Cancellation might not be instant (depends on specific operation implementation). Also, please note that not all operations might support cancellation; in this case `Cancel()` will throw `NotSupportedException`.
335337

336338
### Progress reporting
337339
Library operations support progress reporting via exposing `IAsyncOperation.Progress` property and progress reporting events:
338340
```csharp
339-
var progress = op.Progess; // gets an operation progress as a float value in range [0, 1]
341+
var progress = op.Progress; // gets an operation progress as a float value in range [0, 1]
340342
341343
// subscribe to progress changed event
342344
op.ProgressChanged += (sender, args) =>
@@ -375,7 +377,7 @@ There are also non-delegate completion callbacks (`IAsyncContinuation`):
375377
```csharp
376378
class MyContinuation : IAsyncContinuation
377379
{
378-
public void Invoke(IAsyncOperation op, bool inline) => Debug.Log("Done");
380+
public void Invoke(IAsyncOperation op) => Debug.Log("Done");
379381
}
380382

381383
// ...
@@ -483,7 +485,7 @@ Please note that the library is NOT a replacement for [Tasks](https://docs.micro
483485
- An extendable [IAsyncResult](https://docs.microsoft.com/en-us/dotnet/api/system.iasyncresult) implementation is needed.
484486

485487
## Motivation
486-
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 the like 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 for the best of human kind.
488+
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.
487489

488490
## Documentation
489491
Please see the links below for extended information on the product:

src/Build.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function _PublishAssetStorePackage
6969
param([string]$targetFramework)
7070

7171
$changelogPath = (Join-Path $scriptPath "..\CHANGELOG.md")
72+
$readmePath = (Join-Path $scriptPath "UnityFx.Async\README.txt")
7273
$filesToPublish = (Join-Path $scriptPath "UnityFx.Async.AssetStore\Assets\*")
7374
$binToPublish =(Join-Path $binPath (Join-Path $targetFramework "\*"))
7475
$publishPath = (Join-Path $assetStorePath (Join-Path $targetFramework "Assets"))
@@ -79,9 +80,9 @@ function _PublishAssetStorePackage
7980
Copy-Item -Path $filesToPublish -Destination $publishPath -Force -Recurse
8081
Copy-Item -Path $binToPublish -Destination $publishBinPath -Force -Recurse
8182
Copy-Item -Path $changelogPath -Destination $publishPath2 -Force
83+
Copy-Item -Path $readmePath -Destination $publishPath2 -Force
8284
}
8385

84-
8586
_PublishAssetStorePackage "net35"
8687
_PublishAssetStorePackage "net46"
8788
_PublishAssetStorePackage "netstandard2.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "UnityFx.Async.Unity",
3+
"references": [],
4+
"optionalUnityReferences": [],
5+
"includePlatforms": [],
6+
"excludePlatforms": [],
7+
"allowUnsafeCode": false
8+
}

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

-18
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Alexander Bogarsukov.
2+
// Licensed under the MIT license. See the LICENSE.md file in the project root for more information.
3+
4+
using System;
5+
using UnityEngine;
6+
7+
namespace UnityFx.Async
8+
{
9+
/// <summary>
10+
/// A wrapper for <see cref="AssetBundleCreateRequest"/>.
11+
/// </summary>
12+
public class AssetBundleCreateRequestResult : AsyncOperationResult<AssetBundle>
13+
{
14+
#region data
15+
#endregion
16+
17+
#region interface
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="AssetBundleCreateRequestResult"/> class.
21+
/// </summary>
22+
/// <param name="op">Source web request.</param>
23+
public AssetBundleCreateRequestResult(AssetBundleCreateRequest op)
24+
: base(op)
25+
{
26+
}
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="AssetBundleCreateRequestResult"/> class.
30+
/// </summary>
31+
/// <param name="op">Source web request.</param>
32+
/// <param name="userState">User-defined data.</param>
33+
public AssetBundleCreateRequestResult(AssetBundleCreateRequest op, object userState)
34+
: base(op, userState)
35+
{
36+
}
37+
38+
#endregion
39+
40+
#region AsyncResult
41+
42+
/// <inheritdoc/>
43+
protected override AssetBundle GetResult(AsyncOperation op)
44+
{
45+
return (op as AssetBundleCreateRequest).assetBundle;
46+
}
47+
48+
#endregion
49+
}
50+
}

src/UnityFx.Async.AssetStore/Assets/UnityFx.Async/Scripts/AssetBundleRequestResult{T}.cs

+12-35
Original file line numberDiff line numberDiff line change
@@ -10,63 +10,40 @@ namespace UnityFx.Async
1010
/// A wrapper for <see cref="AssetBundleRequest"/> with result value.
1111
/// </summary>
1212
/// <typeparam name="T">Result type.</typeparam>
13-
public sealed class AssetBundleRequestResult<T> : AsyncResult<T> where T : UnityEngine.Object
13+
public sealed class AssetBundleRequestResult<T> : AsyncOperationResult<T> where T : UnityEngine.Object
1414
{
1515
#region data
16-
17-
private readonly AssetBundleRequest _op;
18-
1916
#endregion
2017

2118
#region interface
2219

2320
/// <summary>
24-
/// Gets the underlying <see cref="AssetBundleRequest"/> instance.
21+
/// Initializes a new instance of the <see cref="AssetBundleRequestResult{T}"/> class.
2522
/// </summary>
26-
public AssetBundleRequest Request
23+
/// <param name="op">Source operation.</param>
24+
public AssetBundleRequestResult(AssetBundleRequest op)
25+
: base(op)
2726
{
28-
get
29-
{
30-
return _op;
31-
}
3227
}
3328

3429
/// <summary>
3530
/// Initializes a new instance of the <see cref="AssetBundleRequestResult{T}"/> class.
3631
/// </summary>
37-
/// <param name="op">Source web request.</param>
38-
public AssetBundleRequestResult(AssetBundleRequest op)
39-
: base(AsyncOperationStatus.Running)
32+
/// <param name="op">Source operation.</param>
33+
/// <param name="userState">User-defined data.</param>
34+
public AssetBundleRequestResult(AssetBundleRequest op, object userState)
35+
: base(op, userState)
4036
{
41-
_op = op;
42-
43-
if (op.isDone)
44-
{
45-
TrySetResult(op.asset as T, true);
46-
}
47-
else
48-
{
49-
#if UNITY_2017_2_OR_NEWER || UNITY_2018
50-
51-
// Starting with Unity 2017.2 there is AsyncOperation.completed event
52-
op.completed += o => TrySetResult(o.asset as T);
53-
54-
#else
55-
56-
AsyncUtility.AddCompletionCallback(op, () => TrySetResult(_op.asset as T));
57-
58-
#endif
59-
}
6037
}
6138

6239
#endregion
6340

64-
#region AsyncResult
41+
#region AsyncOperationResult
6542

6643
/// <inheritdoc/>
67-
protected override float GetProgress()
44+
protected override T GetResult(AsyncOperation op)
6845
{
69-
return _op.progress;
46+
return (op as AssetBundleRequest).asset as T;
7047
}
7148

7249
#endregion

src/UnityFx.Async.AssetStore/Assets/UnityFx.Async/Scripts/AsyncOperationResult.cs

+22-8
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,29 @@ public AsyncOperation Operation
3535
/// </summary>
3636
/// <param name="op">Source web request.</param>
3737
public AsyncOperationResult(AsyncOperation op)
38-
: base(AsyncOperationStatus.Running)
3938
{
4039
_op = op;
40+
}
41+
42+
/// <summary>
43+
/// Initializes a new instance of the <see cref="AsyncOperationResult"/> class.
44+
/// </summary>
45+
/// <param name="op">Source web request.</param>
46+
/// <param name="userState">User-defined data.</param>
47+
public AsyncOperationResult(AsyncOperation op, object userState)
48+
: base(null, userState)
49+
{
50+
_op = op;
51+
}
4152

42-
if (op.isDone)
53+
#endregion
54+
55+
#region AsyncResult
56+
57+
/// <inheritdoc/>
58+
protected override void OnStarted()
59+
{
60+
if (_op.isDone)
4361
{
4462
TrySetCompleted(true);
4563
}
@@ -48,20 +66,16 @@ public AsyncOperationResult(AsyncOperation op)
4866
#if UNITY_2017_2_OR_NEWER || UNITY_2018
4967

5068
// Starting with Unity 2017.2 there is AsyncOperation.completed event
51-
op.completed += o => TrySetCompleted();
69+
_op.completed += o => TrySetCompleted();
5270

5371
#else
5472

55-
AsyncUtility.AddCompletionCallback(op, () => TrySetCompleted());
73+
AsyncUtility.AddCompletionCallback(_op, () => TrySetCompleted());
5674

5775
#endif
5876
}
5977
}
6078

61-
#endregion
62-
63-
#region AsyncResult
64-
6579
/// <inheritdoc/>
6680
protected override float GetProgress()
6781
{

0 commit comments

Comments
 (0)