public void InterlaceError() { var x = 3; var y = 4.57f; var z = 1425.67f; var xx = x * x; var yy = y * y; var zz = z.ToString(); var cw = string.Join(" ", new string[] { xx.ToString(), yy.ToString(), zz }); Corout.WhenAll <int, float, string>(ac => Routines.Failing(x, ac), ac => Routines.GetFloatSquareRoot(y, ac), ac => Routines.GetFloatString(z, ac)) .OnCatch <Exception>((ex, co) => { Debug.Log("catch error"); //throw ex; co.Abort(); }) .ContinueWith(() => Routines.NStepVerbose(10)) //.ContinueWith<string>(Routines.JoinString) //.OnComplete(co => //{ //Debug.Log(co.Result); //Assert.AreEqual(cw, co.Result); //}) .Start(); }
public void Error02() { int x = 15; var y = x * x; var s = y.ToString(); int l = s.Length; Corout.Create <int>(co => Routines.Failing(x, co)) .OnCatch <NotSupportedException>((ex, co) => { Debug.Log("Catch error."); co.Abort(); }) .OnSucceed(co => { Debug.Log("first on succeed."); Assert.AreEqual(co.Result, y); }) .ContinueWith <string>(Routines.GetIntString) .OnSucceed(co => { Debug.Log("second on succeed should not happen."); Assert.AreEqual(co.Result, s); }) .ContinueWith <int>(Routines.GetLength) .OnSucceed(co => { Debug.Log("third on succeed should not happen."); Assert.AreEqual(co.Result, l); }) .Start(); }
public void CatchThrowFinally() { var x = 42; var y = x * x; Corout.Create <int>(co => Routines.Failing(x, co)) .OnCatch <NotSupportedException>((ex, co) => { Assert.IsInstanceOf <NotSupportedException>(ex); Debug.Log("Catch: 'NotSupportedException'."); }) .OnFinally(co => { Assert.IsTrue(co.Faulted); Debug.Log("Finally do some clean-up..."); }) .Start(); Corout.Create <int>(co => Routines.GetIntSquareRoot(x, co)) .OnFinally(co => { Debug.Log("'OnFinally' doesn't need 'OnCatch' and are always executed."); Assert.AreEqual(co.Result, y); Assert.IsTrue(co.Succeeded); }) .Start(); Corout.Create <int>(co => Routines.Failing(x, co)) .OnCatch <NotSupportedException>((ex, co) => { Assert.IsInstanceOf <NotSupportedException>(ex); Assert.IsTrue(co.Faulted); throw ex; }) .OnFinally(co => { Assert.IsTrue(co.Faulted); Debug.Log("Even if you throw exception 'OnFinally' is executed."); }) .Start(); }