| 
246
 | 
     1 using System;
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 namespace Implab {
 | 
| 
 | 
     4     public class PromiseReaction<T> : IResolvable<T> {
 | 
| 
 | 
     5         IDispatcher m_dispatcher;
 | 
| 
 | 
     6 
 | 
| 
 | 
     7         Action<T> m_onFulfilledJob;
 | 
| 
 | 
     8 
 | 
| 
 | 
     9         Action<Exception> m_onRejectedJob;
 | 
| 
 | 
    10 
 | 
| 
 | 
    11         public void Reject(Exception error) {
 | 
| 
 | 
    12             if (m_dispatcher != null)
 | 
| 
 | 
    13                 m_dispatcher.Enqueue(() => m_onRejectedJob(error));
 | 
| 
 | 
    14             else
 | 
| 
 | 
    15                 m_onRejectedJob(error);
 | 
| 
 | 
    16         }
 | 
| 
 | 
    17 
 | 
| 
 | 
    18         public void Resolve(T result) {
 | 
| 
 | 
    19             if (m_dispatcher != null)
 | 
| 
 | 
    20                 m_dispatcher.Enqueue(() => m_onFulfilledJob(result));
 | 
| 
 | 
    21             else
 | 
| 
 | 
    22                 m_onFulfilledJob(result);
 | 
| 
 | 
    23         }
 | 
| 
 | 
    24     }
 | 
| 
 | 
    25 } |