/// <summary> /// Adds a micro thread function to the <paramref name="scriptSystem"/> that executes when the event is published. /// </summary> /// <typeparam name="T">The type of the event handler parameter.</typeparam> /// <param name="scriptSystem">The <see cref="ScriptSystem"/>.</param> /// <param name="eventKey">The event to wait for.</param> /// <param name="action">The micro thread function to execute.</param> /// <param name="priority">The priority of the micro thread action being added.</param> /// <returns>The <see cref="MicroThread"/>.</returns> /// <exception cref="ArgumentNullException"> If <paramref name="scriptSystem"/>, <paramref name="eventKey"/> or <paramref name="action"/> is <see langword="null"/>.</exception> /// <remarks> /// If the <paramref name="action"/> is a <see cref="ScriptComponent"/> instance method the micro thread will be automatically stopped if the <see cref="ScriptComponent"/> or <see cref="Entity"/> is removed. /// </remarks> public static MicroThread AddOnEventTask <T>( this ScriptSystem scriptSystem, EventKey <T> eventKey, Func <T, Task> action, long priority = 0L) { if (scriptSystem == null) { throw new ArgumentNullException(nameof(scriptSystem)); } if (eventKey == null) { throw new ArgumentNullException(nameof(eventKey)); } if (action == null) { throw new ArgumentNullException(nameof(action)); } return(scriptSystem.AddOnEventTask(new EventReceiver <T>(eventKey), action, priority)); }