using System;
using System.Collections.Generic;

namespace %%%PROJECT_ID%%%
{
	public static class AsyncMessageQueue
	{
		public static readonly object MUTEX = new object();

		private static int messageCount = 0;
		private static readonly List<object> messages = new List<object>();

		public static void PushMessage(int messageType, params object[] values)
		{
			lock (MUTEX)
			{
				messages.Add(messageType);
				messages.AddRange(values);
				messageCount++;
			}
		}

		public static object[] PumpMessages()
		{
			object[] messagesCopy = null;
			lock (MUTEX)
			{
				if (messageCount > 0) {
					messages.Insert(0, messageCount);
					messagesCopy = messages.ToArray();
					messages.Clear();
					messageCount = 0;
				}
			}

			return messagesCopy;
		}
	}
}
