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); } } } }
protected bool TryGetResult(UniTask.Awaiter awaiter) { try { awaiter.GetResult(); return(true); } catch (Exception ex) { completionSource.TrySetException(ex); return(false); } }
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); }
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); } }