A set of utilities for Asynchronous programming in Unity.
Use clean, async style web requests with better exception handling instead of coroutine hell.
Provide easier task composition and cancellation.
Provide easy to implement conversion and compatibility with older Coroutine style code.
Most of the entities in Unity API are not thread safe.
Methods from this library are thread aware and will be pushed to Unity's Main thread's synchronization context for execution.
Cancellation of requests is also handled in the safe manner.
Navigate to Player Settings and make sure your Scripting Runtime Version is set to .NET 4.6 Equivalent.
Copy Assets/Plugins folder into your Project's Assets folder.
Simply call WebrequestUtils.();
Theese methods are awaitable, provide cancellation, and are thread safe (posted onto main thread).
public async void Start()
{
var req = await WebRequestUtils.Get("https://ipinfo.io");
Debug.Log(req.ReadToEnd());
}
With .net 4.6 script runtime anything that returns IEnumerator is awaitable.
Can be used like so:
public async void Start()
{
var req = await WaitForSomething();
}
public IEnumerator WaitForSomething()
{
while(isSomethingCompleded)
yield return null;
}
The library is based on this asset.
It was enhanced with support for true async style Http requests.