/// <summary>
        /// Executes the specified action once.
        /// </summary>
        /// <param name="lb">The load balancer.</param>
        /// <param name="action">The action.</param>
        /// <param name="delay">The delay until the action is executed.</param>
        public static void ExecuteOnce(this ILoadBalancer lb, Action action, float delay = 0f)
        {
            Ensure.ArgumentNotNull(action, "action");

            if (_oneTimeActions == null)
            {
                _oneTimeActions = new Queue <RecycledOneTimeAction>(1);
            }

            RecycledOneTimeAction ota;

            if (_oneTimeActions.Count > 0)
            {
                ota        = _oneTimeActions.Dequeue();
                ota.action = action;
            }
            else
            {
                ota = new RecycledOneTimeAction
                {
                    action = action
                };
            }

            if (delay > 0f)
            {
                lb.Add(ota, delay, true);
            }
            else
            {
                lb.Add(ota);
            }
        }
예제 #2
0
 private static void Return(RecycledOneTimeAction action)
 {
     action.action = null;
     _oneTimeActions.Enqueue(action);
 }