Search Unity

Async Task Library for Unity3d : Easy Threading and Coroutines with results !

Discussion in 'Assets and Asset Store' started by nventimiglia, Mar 8, 2015.

  1. nventimiglia

    nventimiglia

    Joined:
    Sep 20, 2011
    Posts:
    153
    https://github.com/NVentimiglia/Unity3d-Async-Task

    Unity3d Async Task Library
    A utility library inspired by the Task Parallelism Library, but made especially for Unity3d. Supports running and waiting on actions running in background threads. Supports running and waiting on coroutines. Supports coroutines with return results and exception messages !

    • Tasks support running on the main thread, background thread or as coroutines.
    • Tasks support return results.
    • Wait for your tasks to complete in a coroutine or as a thread blocking call
    • Graceful exception handling (IsFaulted ?)
    • Works on Windows, Mac, Ios, Android
    • May have issues on WebGL as it does not support threading (but coroutine should work fine.)
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    EDIT: fixed now. thanks.
    https://github.com/NVentimiglia/Unity3d-Async-Task/commit/0a8e84e599f2f7c8a00359e2af6dbb7cc21e6590

    i want to continue my animation while i do my work
    why does it continue with UnityTask.Run but not with UnityTask.Run<bool, bool>?

    thanks a lot!
    this looks great & free :)

    i wonder what parse.com uses to get ContinueWith in unity?

    Code (CSharp):
    1. using Foundation.Tasks;
    2. using UnityEngine;
    3. public class TestTask : MonoBehaviour
    4. {
    5.     [ContextMenu("Work0")]
    6.     public void Work0()
    7.     {
    8.         // works, animation continues
    9.         UnityTask.Run(RealWork).ContinueWith(t => Debug.Log("Done!"));
    10.     }
    11.     [ContextMenu("Work1")]
    12.     public void Work1()
    13.     {
    14.         // does not work. animation freezes
    15.         UnityTask<bool>.Run<bool, bool>(RealWork, false).ContinueWith(t => Debug.Log("Done! " + t.Result));
    16.     }
    17.     private bool RealWork(bool test)
    18.     {
    19.         RealWork();
    20.         return test;
    21.     }
    22.     private void RealWork()
    23.     {
    24.         const int count = 100;
    25.         for (var y = 0; y < count; y++)
    26.         {
    27.             for (var x = 0; x < count; x++)
    28.             {
    29.                 Debug.Log(new Vector2(x, y));
    30.             }
    31.         }
    32.     }
    33. }
    34.  
     
    Last edited: May 26, 2015