AsyncReactAwait
AsyncReactAwait (Ara) is a development suite for asynchronous and reactive C# programming in Unity. It provides IBindable and IMutable interfaces for managing data changes and binding callbacks, along with Promise implementations that offer interface-based alternatives to Task with improved completion control. Ideal for decoupling UI from data models and managing complex async workflows.
com.kekchpek.ara 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/ara.git?path=AraUnityProj/Assets/Packages/com.kekchpek.ara README Markdown
Copy this to your project's README.md
## Installation
Add **AsyncReactAwait** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/ara.git?path=AraUnityProj%2FAssets%2FPackages%2Fcom.kekchpek.ara
```
[](https://www.pkglnk.dev/pkg/ara)README
AsyncReactAwait (Ara)
Ara is the development suit for asynchronous and reactive C# development. It contains classes for convenient data changing and handling management.
Bindable
IBindable and IMutable interfaces are supposed to be used for convenient changes handling of fields and properties
Example
public class HumanModel
{
private IMutable _age = new Mutable();
public IBindable Age => _age; // keep age being mutable only from inside the class
private IMutable _name = new Mutable("No-Name");
public IBindable Name => _name; // keep name being mutable only from inside the class
public void SetName(string newName)
{
_name.Value = newName;
}
public void IncrementAge()
{
_age.Value++;
}
}
public class HumanView : IDisposable
{
private readonly SomeLabel _ageLabel = new SomeLabel();
private readonly SomeLabel _nameLabel = new SomeLabel();
private readonly HumanModel _model;
public HumanView(HumanModel model)
{
_model = model;
_model.Age.Bind(_ageLabel.SetText);
_model.Name.Bind(_nameLabel.SetText);
}
public void Dispose()
{
_model.Age.Unbind(_ageLabel.SetText);
_model.Name.Unbind(_nameLabel.SetText);
}
}
Also IBindable have methods for awaiting some specific value.
Example with async
public class ScoreModel
{
private IMutable<int> _score = new Mutable();
public IBindable Score => _score;
public void AddScore(int score)
{
_score += score;
}
public async void AddBonus(int bonusValue, int requiredScore)
{
await Score.WillBe(s =>
s >= requiredScore);
AddScore(bonusValue);
}
}
Promises
Promises are some kind of a replacement for regular C# Task. They can also be used as a return type for async methods or with await like tasks.
But promises have two advantages:
- Promises have an interface. So you can easely substitute them to some other implementation.
- Promises' completition is easier to control from managed code with
SuccessandFailmethods.
Example
// The third party class for playing animations
public abstract class ThirdPartyAnimation
{
protected void Start() {...}
protected virtual void Ended() {...}
}
// Managed animation implementation.
public class Animation : ThirdPartyAnimation
{
private IControllablePromise _playingPromise;
public async IPromise Play() {
_playingPromise = new ControllablePromise();
Start();
await _playingPromise;
}
protected override void Ended() {
base.Ended();
_playingPromise?.Success();
_playingPromise = null;
}
}
No comments yet. Be the first!