예제 #1
0
파일: ValueTask.cs 프로젝트: Nucs/nlib
 /// <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));
 }
예제 #2
0
 /// <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)));
     }
 }
예제 #3
0
파일: TaskShim.cs 프로젝트: Nucs/nlib
 public static Task <T> FromResult <T>(T value)
 {
     return(Tasky.FromResult(value));
 }