AIR's solution for handing operations with late completion.
At its core this provides interfaces with no return or a single generic return value, for wrapping an operation so that a following action can be scheduled via .Then. Beyond dealing with long running, external, or parallel processes, Async can also be used to organise the sequence of actions or the flow of data in one place before sending off those instructions to run.
The package also includes:
Immediate; an async that isn't async. Makes writing tests easy.AsyncProgress; an async that can return percentage completion.AsyncHandleUnion; takes multiple Asyncs and only invokes itsThenwhen all of the Asyncs it holds have completed.Async.Catch; an optional method to signal failure of the Async or theThen.
There are two sides to this;
- How an Async concretion is made, prepared, and returned via it's interface.
- How an IAsync is received and bound.
public class Foo
{
private AsyncHandle _asyncHandle = new AsyncHandle();
public IAsync Async => _asyncHandle;
public void FlushProcessResults(List<Datum> data)
{
//some long running process
foreach (var item in data)
{
// something
}
_asyncHandle.Complete();
}
}var asyncHandle = Foo.Async; //the property from our previous fragment
asyncHandle.Then(() => Notification.Information("Results have Flushed"));Note: If the async has already completed before the .Then, the ThenHandler is called immediately.
Add to unity via the package manager. Use 'Add git package' with https://github.com/AnImaginedReality/Async.git.