コード例 #1
0
        void EnsureInitializedCore()
        {
            lock (syncLock)
            {
                if (!Volatile.Read(ref initialized))
                {
                    var f = Interlocked.Exchange(ref taskFactory, null);
                    if (f != null)
                    {
                        var task    = f();
                        var awaiter = task.GetAwaiter();
                        if (awaiter.IsCompleted)
                        {
                            SetCompletionSource(awaiter);
                        }
                        else
                        {
                            this.awaiter = awaiter;
                            awaiter.SourceOnCompleted(continuation, this);
                        }

                        Volatile.Write(ref initialized, true);
                    }
                }
            }
        }
コード例 #2
0
 protected bool TryGetResult(UniTask.Awaiter awaiter)
 {
     try {
         awaiter.GetResult();
         return(true);
     }
     catch (Exception ex) {
         completionSource.TrySetException(ex);
         return(false);
     }
 }
コード例 #3
0
ファイル: UniTask.Factory.cs プロジェクト: WARP-D/Hikari
            public UniTaskStatus GetStatus(short token)
            {
                var f = Interlocked.Exchange(ref factory, null);

                if (f == null)
                {
                    throw new InvalidOperationException("Can't call twice.");
                }

                task    = f();
                awaiter = f().GetAwaiter();
                return(task.Status);
            }
コード例 #4
0
        internal AsyncLazy(UniTask task)
        {
            this.taskFactory      = null;
            this.completionSource = new UniTaskCompletionSource();
            this.syncLock         = null;
            this.initialized      = true;

            var awaiter = task.GetAwaiter();

            if (awaiter.IsCompleted)
            {
                SetCompletionSource(awaiter);
            }
            else
            {
                this.awaiter = awaiter;
                awaiter.SourceOnCompleted(continuation, this);
            }
        }