Created
August 15, 2014 20:24
-
-
Save RoyAwesome/983dce62feb7f7ac8fdc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections.Generic; | |
using System; | |
public class Dispatcher : MonoBehaviour { | |
Queue<Action> JoinActions = new Queue<Action>(); | |
public static Dispatcher Instance = null; | |
// Use this for initialization | |
void Start () { | |
Instance = this; | |
} | |
// Update is called once per frame | |
void Update () | |
{ | |
lock(JoinActions) | |
{ | |
if(JoinActions.Count > 0) | |
{ | |
do | |
{ | |
Action a = JoinActions.Dequeue(); | |
try | |
{ | |
a(); | |
} | |
catch (Exception e) | |
{ | |
Debug.LogError(e.ToString()); | |
} | |
} while (JoinActions.Count > 0); | |
} | |
} | |
} | |
public static void Dispatch(Action a) | |
{ | |
lock(Instance.JoinActions) | |
{ | |
Instance.JoinActions.Enqueue(a); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment