Skip to content

Commit f59cb44

Browse files
committed
don't interrupt the whole scheduled batch if one of the callbacks throws. just log the exception instead (see #38)
also update Unity and add some minor cosmetic changes
1 parent 9b2481f commit f59cb44

File tree

3 files changed

+45
-6
lines changed

3 files changed

+45
-6
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
m_EditorVersion: 2021.3.45f1
2-
m_EditorVersionWithRevision: 2021.3.45f1 (0da89fac8e79)
1+
m_EditorVersion: 2021.3.45f2
2+
m_EditorVersionWithRevision: 2021.3.45f2 (88f88f591b2e)

src/TinkState-Unity/Runtime/UnityBatchScheduler.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ void Progress(float maxSeconds)
5050
// we have two queues and swap between them to avoid allocating a new list every time
5151
var currentQueue = queue;
5252
queue = nextQueue;
53-
foreach (var o in currentQueue) o.Run();
53+
foreach (var o in currentQueue)
54+
{
55+
try
56+
{
57+
o.Run();
58+
}
59+
catch (Exception e)
60+
{
61+
Debug.LogException(e);
62+
}
63+
}
5464
currentQueue.Clear();
5565
nextQueue = currentQueue;
5666
}
@@ -62,7 +72,7 @@ void Progress(float maxSeconds)
6272
}
6373
}
6474

65-
float GetTimeStamp()
75+
static float GetTimeStamp()
6676
{
6777
return Time.realtimeSinceStartup;
6878
}
@@ -95,7 +105,7 @@ static PlayerLoopSystem[] AppendLoopSystem(PlayerLoopSystem[] subSystemList, Pla
95105

96106
static int FindLoopSystemIndex(PlayerLoopSystem[] subSystemList, Type systemType)
97107
{
98-
for (int i = 0; i < subSystemList.Length; i++)
108+
for (var i = 0; i < subSystemList.Length; i++)
99109
{
100110
if (subSystemList[i].type == systemType)
101111
{

src/TinkState-Unity/Tests/TestUnityBatchScheduler.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Collections;
3+
using System.Collections.Generic;
24
using NUnit.Framework;
35
using UnityEngine.TestTools;
46
using TinkState;
@@ -104,4 +106,31 @@ void BindCallback(int value)
104106
yield return null;
105107
Assert.That(bindingCalls, Is.EqualTo(3));
106108
}
107-
}
109+
110+
111+
[UnityTest]
112+
public IEnumerator TestBindingExceptionNotStoppingProcessing()
113+
{
114+
var state = Observable.State(10);
115+
var calls = new List<string>();
116+
var binding1Called = false;
117+
state.Bind(value =>
118+
{
119+
if (!binding1Called)
120+
{
121+
binding1Called = true;
122+
calls.Add("a");
123+
}
124+
else throw new Exception("FAIL");
125+
});
126+
state.Bind(value =>
127+
{
128+
calls.Add("b");
129+
});
130+
Assert.That(calls, Is.EquivalentTo(new [] {"a", "b"}));
131+
state.Value = 15;
132+
yield return null;
133+
LogAssert.Expect(LogType.Exception, "Exception: FAIL");
134+
Assert.That(calls, Is.EquivalentTo(new [] {"a", "b", "b"}));
135+
}
136+
}

0 commit comments

Comments
 (0)