Skip to content

Commit

Permalink
Merge branch 'release/0.9.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Arvtesh committed Apr 24, 2018
2 parents 2e1bfaa + b19f59f commit ae72add
Show file tree
Hide file tree
Showing 70 changed files with 8,149 additions and 3,814 deletions.
28 changes: 27 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/); this project adheres to [Semantic Versioning](http://semver.org/).

-----------------------
## [Unreleased]
## [0.9.0] - Unreleased

### Added
- Added `AsyncContinuationOptions`.
- Added `AsyncCreationOptions`.
- Added `Promise`-like extensions `Then`, `ThenAll`, `ThenAny`, `Rebind`, `Catch`, `Finally` and `Done`.
- Added `Unwrap` extension methods.
- Added `FromTask`/`FromObservable` helpers.
- Added `FromAction` helpers.
- Added `ToAsync` extension method for `IObservable` interface.
- Added `TryAddContinuation`/`RemoveContinuation` methods to `IAsyncOperationEvents` for non-delegate continuations.
- Added `IAsyncUpdatable` and `IAsyncUpdateSource` interfaces.
- Added `Delay`/`Retry` overload that uses `IAsyncUpdateSource`-based service for time management.
- Added cancellation support (`IAsyncCancellable` interface, `WithCancellation` extension method and many implementation changes).
- Added `Wait`/`Join` overloads with `CancellationToken` argument.

### Changed
- Changed `ContinueWith` extension signatures to match corresponding `Task` methods.
- Changed `IAsyncOperation.Exception` to always return an exception instance if completed with non-success.
- Changed `AddCompletionCallback`/`AddContinuation` to instance methods (instead of extensions).

### Fixed
- Fixed exception not initialized properly for canceled operations sometimes.

### Removed
- Removed `GetAwaiter`/`ConfigureAwait` instance methods from `AsyncResult` to avoid code duplication (extension methods should be used).
- Removed all `AsyncCompletionSource` methods having `completedSynchronously` argument.

-----------------------
## [0.8.2] - 2018-03-28
Expand Down
523 changes: 421 additions & 102 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public static GameObject GetRootGo()
return _go;
}

/// <summary>
/// Returns an instance of an <see cref="IAsyncUpdateSource"/>.
/// </summary>
public static IAsyncUpdateSource GetDefaultUpdateSource()
{
return GetCoroutineRunner();
}

/// <summary>
/// Starts a coroutine.
/// </summary>
Expand Down Expand Up @@ -209,11 +217,21 @@ internal static void AddCompletionCallback(WWW request, Action completionCallbac

#region implementation

private class CoroutineRunner : MonoBehaviour
private class CoroutineRunner : MonoBehaviour, IAsyncUpdateSource
{
#region data

private Dictionary<object, Action> _ops;
private List<object> _opsToRemove;
private List<Action> _updateCallbacks;
private List<Action> _updateCallbacksToRemove;
private List<IAsyncUpdatable> _updatables;
private List<IAsyncUpdatable> _updatablesToRemove;
private bool _updating;

#endregion

#region interface

public void AddCompletionCallback(object op, Action cb)
{
Expand All @@ -231,72 +249,157 @@ public void AddUpdateCallback(Action updateCallback)
if (_updateCallbacks == null)
{
_updateCallbacks = new List<Action>();
_updateCallbacksToRemove = new List<Action>();
}

_updateCallbacks.Add(updateCallback);
}

public void RemoveUpdateCallback(Action updateCallback)
{
_updateCallbacks.Remove(updateCallback);
if (_updating)
{
if (updateCallback != null)
{
_updateCallbacksToRemove.Add(updateCallback);
}
}
else
{
_updateCallbacks.Remove(updateCallback);
}
}

#endregion

#region MonoBehavoiur

private void Update()
{
if (_ops != null && _ops.Count > 0)
try
{
foreach (var item in _ops)
_updating = true;

if (_ops != null && _ops.Count > 0)
{
if (item.Key is AsyncOperation)
foreach (var item in _ops)
{
var asyncOp = item.Key as AsyncOperation;

if (asyncOp.isDone)
if (item.Key is AsyncOperation)
{
item.Value();
_opsToRemove.Add(asyncOp);
var asyncOp = item.Key as AsyncOperation;

if (asyncOp.isDone)
{
item.Value();
_opsToRemove.Add(asyncOp);
}
}
}
#if UNITY_5_2_OR_NEWER || UNITY_5_3_OR_NEWER || UNITY_2017 || UNITY_2018
else if (item.Key is UnityWebRequest)
{
var asyncOp = item.Key as UnityWebRequest;
else if (item.Key is UnityWebRequest)
{
var asyncOp = item.Key as UnityWebRequest;

if (asyncOp.isDone)
if (asyncOp.isDone)
{
item.Value();
_opsToRemove.Add(asyncOp);
}
}
#endif
else if (item.Key is WWW)
{
item.Value();
_opsToRemove.Add(asyncOp);
var asyncOp = item.Key as WWW;

if (asyncOp.isDone)
{
item.Value();
_opsToRemove.Add(asyncOp);
}
}
}
#endif
else if (item.Key is WWW)

foreach (var item in _opsToRemove)
{
var asyncOp = item.Key as WWW;
_ops.Remove(item);
}

if (asyncOp.isDone)
{
item.Value();
_opsToRemove.Add(asyncOp);
}
_opsToRemove.Clear();
}

if (_updateCallbacks != null)
{
foreach (var callback in _updateCallbacks)
{
callback();
}

foreach (var callback in _updateCallbacksToRemove)
{
_updateCallbacksToRemove.Remove(callback);
}

_updateCallbacksToRemove.Clear();
}

foreach (var item in _opsToRemove)
if (_updatables != null)
{
_ops.Remove(item);
var frameTime = Time.deltaTime;

foreach (var item in _updatables)
{
item.Update(frameTime);
}

foreach (var item in _updatablesToRemove)
{
_updatablesToRemove.Remove(item);
}

_updatablesToRemove.Clear();
}
}
finally
{
_updating = false;
}
}

#endregion

#region IAsyncUpdateSource

_opsToRemove.Clear();
public void AddListener(IAsyncUpdatable updatable)
{
if (updatable == null)
{
throw new ArgumentNullException("updatable");
}

if (_updateCallbacks != null)
if (_updatables == null)
{
foreach (var callback in _updateCallbacks)
_updatables = new List<IAsyncUpdatable>();
_updatablesToRemove = new List<IAsyncUpdatable>();
}

_updatables.Add(updatable);
}

public void RemoveListener(IAsyncUpdatable updatable)
{
if (_updating)
{
if (updatable != null)
{
callback();
_updatablesToRemove.Add(updatable);
}
}
else
{
_updatables.Remove(updatable);
}
}

#endregion
}

private static CoroutineRunner GetCoroutineRunner()
Expand Down
Loading

0 comments on commit ae72add

Please sign in to comment.