Esempio n. 1
0
        public static TaskAwaiter GetAwaiter(this GoogleDriveRequestYeildInstruction yeildInstruction)
        {
            var taskCompletionSource = new TaskCompletionSource<object>();

            if (yeildInstruction.IsDone) { taskCompletionSource.SetResult(null); }
            else { yeildInstruction.OnDoneNonGeneric += () => taskCompletionSource.SetResult(null); }

            return (taskCompletionSource.Task as Task).GetAwaiter();
        }
Esempio n. 2
0
 /// <summary>
 /// Begin communicating with the Google Drive API to execute the request.
 /// </summary>
 /// <returns>
 /// A yeild instruction indicating the progress/completion state of the request.
 /// Yield this object to wait until the request <see cref="IsDone"/> or use <see cref="OnDone"/> event.
 /// </returns>
 public GoogleDriveRequestYeildInstruction <TResponse> Send()
 {
     if (!IsRunning)
     {
         yeildInstruction = new GoogleDriveRequestYeildInstruction <TResponse>(this);
         SendWebRequest();
     }
     return(yeildInstruction);
 }
Esempio n. 3
0
    /// <summary>
    /// Allows awaiting <see cref="GoogleDriveRequest"/> objects in async methods.
    /// </summary>
    public static TaskAwaiter<TResponse> GetAwaiter<TResponse> (this GoogleDriveRequestYeildInstruction<TResponse> yeildInstruction)
        {
            var taskCompletionSource = new TaskCompletionSource<TResponse>();

            if (yeildInstruction.GoogleDriveRequest.IsDone) { taskCompletionSource.SetResult(yeildInstruction.GoogleDriveRequest.ResponseData); }
            else { yeildInstruction.OnDone += responseData => taskCompletionSource.SetResult(responseData); }

            return taskCompletionSource.Task.GetAwaiter();
        }