/// <summary> /// Gets a <see cref="Task{TResult}"/> object to represent this ValueTask. It will /// either return the wrapped task object if one exists, or it'll manufacture a new /// task object to represent the result. /// </summary> public Task <TResult> AsTask() { // Return the task if we were constructed from one, otherwise manufacture one. We don't // cache the generated task into _task as it would end up changing both equality comparison // and the hash code we generate in GetHashCode. return(_task ?? Tasky.FromResult(_result)); }
/// <summary> /// Asynchronously waits for this event to be set. /// </summary> public Task <bool> WaitAsync(int millisecondsTimeout) { lock (_sync) { if (IsSet) { return(Tasky.FromResult(true)); } var ret = _tcs.Task; //Enlightenment.Trace.AsyncManualResetEvent_Wait(this, ret); return(Tasky.Run(() => ret.Wait(millisecondsTimeout))); } }
public static Task <T> FromResult <T>(T value) { return(Tasky.FromResult(value)); }