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); } } } }
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); } }
public void OnCompleted(Action <object> continuation, object state, short token) { awaiter.SourceOnCompleted(continuation, state); }