https://github.com/hellokitty/unitysync.async
Unitysync.Async is an async extension library that allows you to use Task and Task<T> with continuations in Unity3D.
https://github.com/hellokitty/unitysync.async
Last synced: about 1 year ago
JSON representation
Unitysync.Async is an async extension library that allows you to use Task and Task<T> with continuations in Unity3D.
- Host: GitHub
- URL: https://github.com/hellokitty/unitysync.async
- Owner: HelloKitty
- License: mit
- Created: 2017-08-18T07:29:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2020-06-25T12:33:42.000Z (almost 6 years ago)
- Last Synced: 2025-04-09T07:16:41.200Z (about 1 year ago)
- Language: C#
- Homepage:
- Size: 845 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Unitysync.Async
Unitysync.Async is an async extension library that allows you to use Task and Task\ with continuations in Unity3D.
## How to Use
If you have an async method that returns a Task or Task\ then you can register a continuation with an extension method. You can provide various continuation types such as: Action, Action\, Func\, Func\> and of course supports method delegates/lambdas.
The way this works is it starts a coroutine on the current Monobehaviour, using the Monobehaviour as a context for the continuation, and fires off the delegate once the async method has completed and the Task completition state is complete.
```csharp
Service.DoSomethingAsync(someData, someMoreData)
.UnityAsyncContinueWith(this, LogAndDipatchResult);
```
```csharp
Service.DoSomethingAsync(someData, someMoreData)
.UnityAsyncContinueWith(this, result => SomeEntity.SetResult(result.Something));
```
You can schedule multiple continuations on a single Task but the order of their execution is currently undefined if you schedule multiple on the same task.
You can even do a continuation into an async method which will of course return a Task\ which can be continued on again, in a fluent method chaining pattern, and this execution order is defined since they are different tasks.
```csharp
QueryClient.GetAvatarUrl(entityId) //async method that returns an endpoint
.UnityAsyncContinueWith(this, GetAvatar2DImage) //async method that queries the endpoint for the avatar image
.UnityAsyncContinueWith(this, InitializeAvatarMaterials); //non-async method that initializes the avatar materials
```
## Setup
To compile or open Unitysync.Async project you'll first need a couple of things:
* Visual Studio 2017
* Unity 2017.1 with .NET 4.6 enabled
## Builds
NuGet: [Unitysync.Async](https://www.nuget.org/packages/Unitysync.Async/)
Myget: [](https://www.myget.org/)
## Tests
TODO actual tests