view Implab/PromiseAwaiterT.cs @ 245:b904e0a3ba72 v3

working on promises
author cin
date Fri, 26 Jan 2018 04:13:34 +0300
parents cbe10ac0731e
children
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.IsFulfilled;
            }
        }
    }
}