view Implab/PromiseAwaiterT.cs @ 209:a867536c68fc v2

Bound promise to CancellationToken Added new states to ExecutionSate enum. Added Safe.Guard() method to handle cleanup of the result of the promise
author cin
date Wed, 16 Nov 2016 03:06:08 +0300
parents ec91a6dfa5b3
children cbe10ac0731e
line wrap: on
line source

using System;
using System.Runtime.CompilerServices;

namespace Implab {
    public struct PromiseAwaiter<T> : INotifyCompletion {
        readonly IPromise<T> m_promise;

        public PromiseAwaiter(IPromise<T> promise) {
            m_promise = promise;
        }

        public void OnCompleted (Action continuation) {
            if (m_promise != null)
                m_promise.On(continuation, PromiseEventType.All);
        }

        public T GetResult() {
            return m_promise.Join();
        }

        public bool IsCompleted {
            get {
                return m_promise.IsResolved;
            }
        }
    }
}