view Implab/PromiseAwaiter.cs @ 221:8808383fcb94 v2

fixed recursion in Safe.Dispose with IEnumerable
author cin
date Fri, 23 Jun 2017 01:03:42 +0300
parents ec91a6dfa5b3
children cbe10ac0731e
line wrap: on
line source

using System;
using System.Runtime.CompilerServices;

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

        public PromiseAwaiter(IPromise promise) {
            m_promise = promise;
        }

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

        public void GetResult() {
            m_promise.Join();
        }

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