예제 #1
0
 public static void ExecuteOnce(this ILoadBalancer lb, Action action, float delay = 0f)
 {
     LoadBalancedActionPool.RecycledOneTimeAction recycledOneTimeAction;
     Ensure.ArgumentNotNull(action, "action");
     if (LoadBalancedActionPool._oneTimeActions == null)
     {
         LoadBalancedActionPool._oneTimeActions = new Queue <LoadBalancedActionPool.RecycledOneTimeAction>(1);
     }
     if (LoadBalancedActionPool._oneTimeActions.Count <= 0)
     {
         recycledOneTimeAction = new LoadBalancedActionPool.RecycledOneTimeAction()
         {
             action = action
         };
     }
     else
     {
         recycledOneTimeAction        = LoadBalancedActionPool._oneTimeActions.Dequeue();
         recycledOneTimeAction.action = action;
     }
     if (delay <= 0f)
     {
         lb.Add(recycledOneTimeAction);
         return;
     }
     lb.Add(recycledOneTimeAction, delay, true);
 }
예제 #2
0
 private static void Return(LoadBalancedActionPool.RecycledOneTimeAction action)
 {
     action.action = null;
     LoadBalancedActionPool._oneTimeActions.Enqueue(action);
 }