Compare commits

..

No commits in common. "7501ffaf9c02e6dd74dbb9aa2f2197f166f4960a" and "fe9e5c658aca6cc4784e55e3f294ee0a9393785a" have entirely different histories.

7 changed files with 24 additions and 44 deletions

View file

@ -84,7 +84,7 @@ namespace Coroutine {
} }
internal bool OnEvent(Event evt) { internal bool OnEvent(Event evt) {
if (!this.WasCanceled && object.Equals(this.current.Event, evt)) if (!this.WasCanceled && Equals(this.current.Event, evt))
this.MoveNext(); this.MoveNext();
return this.IsFinished; return this.IsFinished;
} }

View file

@ -2,7 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net45;netstandard2.0;net6.0</TargetFrameworks> <TargetFrameworks>net45;netstandard2.0;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
@ -14,7 +13,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile> <PackageReadmeFile>README.md</PackageReadmeFile>
<PackageIcon>Logo.png</PackageIcon> <PackageIcon>Logo.png</PackageIcon>
<VersionPrefix>2.1.5</VersionPrefix> <VersionPrefix>2.1.4</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -11,48 +11,42 @@ namespace Coroutine {
private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance(); private static readonly CoroutineHandlerInstance Instance = new CoroutineHandlerInstance();
/// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/> /// <inheritdoc cref="CoroutineHandlerInstance.TickingCount"/>
public static int TickingCount => CoroutineHandler.Instance.TickingCount; public static int TickingCount => Instance.TickingCount;
/// <inheritdoc cref="CoroutineHandlerInstance.EventCount"/> /// <inheritdoc cref="CoroutineHandlerInstance.EventCount"/>
public static int EventCount => CoroutineHandler.Instance.EventCount; public static int EventCount => Instance.EventCount;
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerable{Wait},string,int)"/> /// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerable{Wait},string,int)"/>
public static ActiveCoroutine Start(IEnumerable<Wait> coroutine, string name = "", int priority = 0) { public static ActiveCoroutine Start(IEnumerable<Wait> coroutine, string name = "", int priority = 0) {
return CoroutineHandler.Instance.Start(coroutine, name, priority); return Instance.Start(coroutine, name, priority);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerator{Wait},string,int)"/> /// <inheritdoc cref="CoroutineHandlerInstance.Start(IEnumerator{Wait},string,int)"/>
public static ActiveCoroutine Start(IEnumerator<Wait> coroutine, string name = "", int priority = 0) { public static ActiveCoroutine Start(IEnumerator<Wait> coroutine, string name = "", int priority = 0) {
return CoroutineHandler.Instance.Start(coroutine, name, priority); return Instance.Start(coroutine, name, priority);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater(Wait,Action,string,int)"/> /// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater"/>
public static ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) { public static ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
return CoroutineHandler.Instance.InvokeLater(wait, action, name, priority); return Instance.InvokeLater(wait, action, name, priority);
}
/// <inheritdoc cref="CoroutineHandlerInstance.InvokeLater(Event,Action,string,int)"/>
public static ActiveCoroutine InvokeLater(Event evt, Action action, string name = "", int priority = 0) {
return CoroutineHandler.Instance.InvokeLater(evt, action, name, priority);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(double)"/> /// <inheritdoc cref="CoroutineHandlerInstance.Tick(double)"/>
public static void Tick(double deltaSeconds) { public static void Tick(double deltaSeconds) {
CoroutineHandler.Instance.Tick(deltaSeconds); Instance.Tick(deltaSeconds);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/> /// <inheritdoc cref="CoroutineHandlerInstance.Tick(TimeSpan)"/>
public static void Tick(TimeSpan delta) { public static void Tick(TimeSpan delta) {
CoroutineHandler.Instance.Tick(delta); Instance.Tick(delta);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/> /// <inheritdoc cref="CoroutineHandlerInstance.RaiseEvent"/>
public static void RaiseEvent(Event evt) { public static void RaiseEvent(Event evt) {
CoroutineHandler.Instance.RaiseEvent(evt); Instance.RaiseEvent(evt);
} }
/// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/> /// <inheritdoc cref="CoroutineHandlerInstance.GetActiveCoroutines"/>
public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() { public static IEnumerable<ActiveCoroutine> GetActiveCoroutines() {
return CoroutineHandler.Instance.GetActiveCoroutines(); return Instance.GetActiveCoroutines();
} }
} }

View file

@ -75,20 +75,7 @@ namespace Coroutine {
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param> /// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
/// <returns>An active coroutine object representing this coroutine</returns> /// <returns>An active coroutine object representing this coroutine</returns>
public ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) { public ActiveCoroutine InvokeLater(Wait wait, Action action, string name = "", int priority = 0) {
return this.Start(CoroutineHandlerInstance.InvokeLaterImpl(wait, action), name, priority); return this.Start(InvokeLaterImpl(wait, action), name, priority);
}
/// <summary>
/// Causes the given action to be invoked after the given <see cref="Event"/>.
/// This is equivalent to a coroutine that waits for the given wait and then executes the given <see cref="Action"/>.
/// </summary>
/// <param name="evt">The event to wait for</param>
/// <param name="action">The action to execute after waiting</param>
/// <param name="name">The <see cref="ActiveCoroutine.Name"/> that the underlying coroutine should have. Defaults to an empty string.</param>
/// <param name="priority">The <see cref="ActiveCoroutine.Priority"/> that the underlying coroutine should have. The higher the priority, the earlier it is advanced compared to other coroutines that advance around the same time. Defaults to 0.</param>
/// <returns>An active coroutine object representing this coroutine</returns>
public ActiveCoroutine InvokeLater(Event evt, Action action, string name = "", int priority = 0) {
return this.InvokeLater(new Wait(evt), action, name, priority);
} }
/// <summary> /// <summary>

View file

@ -9,19 +9,19 @@ namespace Example {
private static readonly Event TestEvent = new Event(); private static readonly Event TestEvent = new Event();
public static void Main() { public static void Main() {
var seconds = CoroutineHandler.Start(Example.WaitSeconds(), "Awesome Waiting Coroutine"); var seconds = CoroutineHandler.Start(WaitSeconds(), "Awesome Waiting Coroutine");
CoroutineHandler.Start(Example.PrintEvery10Seconds(seconds)); CoroutineHandler.Start(PrintEvery10Seconds(seconds));
CoroutineHandler.Start(Example.EmptyCoroutine()); CoroutineHandler.Start(EmptyCoroutine());
CoroutineHandler.InvokeLater(new Wait(5), () => { CoroutineHandler.InvokeLater(new Wait(5), () => {
Console.WriteLine("Raising test event"); Console.WriteLine("Raising test event");
CoroutineHandler.RaiseEvent(Example.TestEvent); CoroutineHandler.RaiseEvent(TestEvent);
}); });
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("Example event received")); CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("Example event received"));
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5); CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked after 'Example event received'"), priority: -5);
CoroutineHandler.InvokeLater(new Wait(Example.TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2); CoroutineHandler.InvokeLater(new Wait(TestEvent), () => Console.WriteLine("I am invoked before 'Example event received'"), priority: 2);
var lastTime = DateTime.Now; var lastTime = DateTime.Now;
while (true) { while (true) {
@ -38,7 +38,7 @@ namespace Example {
Console.WriteLine("After 1 second " + DateTime.Now); Console.WriteLine("After 1 second " + DateTime.Now);
yield return new Wait(9); yield return new Wait(9);
Console.WriteLine("After 10 seconds " + DateTime.Now); Console.WriteLine("After 10 seconds " + DateTime.Now);
CoroutineHandler.Start(Example.NestedCoroutine()); CoroutineHandler.Start(NestedCoroutine());
yield return new Wait(5); yield return new Wait(5);
Console.WriteLine("After 5 more seconds " + DateTime.Now); Console.WriteLine("After 5 more seconds " + DateTime.Now);
yield return new Wait(10); yield return new Wait(10);

View file

@ -128,7 +128,7 @@ namespace Tests {
var p = CoroutineHandler.Start(Parent()); var p = CoroutineHandler.Start(Parent());
CoroutineHandler.RaiseEvent(onParentCreated); CoroutineHandler.RaiseEvent(onParentCreated);
// Nested corotuine starting in OnFinished. // Nested corotuine starting in OnFinished.
p.OnFinished += _ => { p.OnFinished += ac => {
CoroutineHandler.Start(Child()); CoroutineHandler.Start(Child());
CoroutineHandler.RaiseEvent(onChildCreated); CoroutineHandler.RaiseEvent(onChildCreated);
}; };

View file

@ -164,7 +164,7 @@ namespace Tests {
// Nested corotuine starting. // Nested corotuine starting.
var p = CoroutineHandler.Start(Parent()); var p = CoroutineHandler.Start(Parent());
// Nested corotuine starting in OnFinished. // Nested corotuine starting in OnFinished.
p.OnFinished += _ => CoroutineHandler.Start(Child()); p.OnFinished += ac => CoroutineHandler.Start(Child());
} }
var always = CoroutineHandler.Start(AlwaysRunning()); var always = CoroutineHandler.Start(AlwaysRunning());
@ -408,7 +408,7 @@ namespace Tests {
var p = CoroutineHandler.Start(Parent()); var p = CoroutineHandler.Start(Parent());
CoroutineHandler.RaiseEvent(onParentCreated); CoroutineHandler.RaiseEvent(onParentCreated);
// Nested corotuine starting in OnFinished. // Nested corotuine starting in OnFinished.
p.OnFinished += _ => { p.OnFinished += ac => {
CoroutineHandler.Start(Child()); CoroutineHandler.Start(Child());
CoroutineHandler.RaiseEvent(onChildCreated); CoroutineHandler.RaiseEvent(onChildCreated);
}; };