Mercurial > pub > ImplabNet
comparison Implab.Test/AsyncTests.cs @ 138:f75cfa58e3d4 v2
added ICancellable.Cancel(Exception) to allow specify the reason of cancellation
author | cin |
---|---|
date | Tue, 17 Feb 2015 18:16:26 +0300 |
parents | e9e7940c7d98 |
children | 706fccb85524 |
comparison
equal
deleted
inserted
replaced
137:238e15580926 | 138:f75cfa58e3d4 |
---|---|
51 [TestMethod] | 51 [TestMethod] |
52 public void CancelExceptionTest() { | 52 public void CancelExceptionTest() { |
53 var p = new Promise<bool>(); | 53 var p = new Promise<bool>(); |
54 p.Cancel(); | 54 p.Cancel(); |
55 | 55 |
56 var p2 = p.Cancelled(() => { | 56 var p2 = p.Then(x => x, null, reason => { |
57 throw new ApplicationException("CANCELLED"); | 57 throw new ApplicationException("CANCELLED"); |
58 }); | 58 }); |
59 | 59 |
60 try { | 60 try { |
61 p2.Join(); | 61 p2.Join(); |
70 public void ContinueOnCancelTest() { | 70 public void ContinueOnCancelTest() { |
71 var p = new Promise<bool>(); | 71 var p = new Promise<bool>(); |
72 p.Cancel(); | 72 p.Cancel(); |
73 | 73 |
74 var p2 = p | 74 var p2 = p |
75 .Cancelled<bool>(() => { | 75 .Then<bool>(x => x, null, reason => { |
76 throw new ApplicationException("CANCELLED"); | 76 throw new ApplicationException("CANCELLED"); |
77 }) | 77 }) |
78 .Error(e => true); | 78 .Then(x => x, e => true); |
79 | 79 |
80 Assert.AreEqual(true, p2.Join()); | 80 Assert.AreEqual(true, p2.Join()); |
81 } | 81 } |
82 | 82 |
83 [TestMethod] | 83 [TestMethod] |
114 | 114 |
115 [TestMethod] | 115 [TestMethod] |
116 public void FixErrorTest() { | 116 public void FixErrorTest() { |
117 var p = new Promise<int>(); | 117 var p = new Promise<int>(); |
118 | 118 |
119 var p2 = p.Error(e => 101); | 119 var p2 = p.Then(x => x, e => 101); |
120 | 120 |
121 p.Reject(new Exception()); | 121 p.Reject(new Exception()); |
122 | 122 |
123 Assert.AreEqual(p2.Join(), 101); | 123 Assert.AreEqual(p2.Join(), 101); |
124 } | 124 } |
758 pSurvive.Resolve(false); | 758 pSurvive.Resolve(false); |
759 return s; | 759 return s; |
760 }); | 760 }); |
761 | 761 |
762 result | 762 result |
763 .Cancelled(() => pSurvive.Resolve(true)); | 763 .On(() => pSurvive.Resolve(true), PromiseEventType.Cancelled); |
764 | 764 |
765 return result; | 765 return result; |
766 }); | 766 }); |
767 | 767 |
768 hemStarted.WaitOne(); | 768 hemStarted.WaitOne(); |