void GetCompleteLeaderboardAux(int offset, TaskCompletionSource <bool> tcs, Action <int, string> intermediateResult)
 {
     if (m_stopProcessing)
     {
         m_stopProcessing = false;
         tcs.SetError(new Exception("User cancelled"));
     }
     else
     {
         StartCoroutine(ConnectToAPI(offset, tcs, intermediateResult));
     }
 }
    IEnumerator ConnectToAPI(int offset, TaskCompletionSource <bool> tcs, Action <int, string> intermediateResult)
    {
        yield return(StartCoroutine(YOUR_FAVORITE_API_GetLeaderBoardUsingWWW(offset, queryLimit)));

        SortedList <int, string> result = YOUR_FAVORITE_API_GetResultsFromCall();

        if (result == null)
        {               // mockup an error in the API
            tcs.SetError(new Exception("API returns NULL"));
        }

        foreach (int k in result.Keys)
        {
            intermediateResult(k, result[k]);
        }
        if (result.Count == queryLimit)
        {
            GetCompleteLeaderboardAux(offset + queryLimit, tcs, intermediateResult);
        }
        else
        {
            tcs.SetResult(true);
        }
    }
Example #3
0
		/// <summary>
		/// Creates a continuation that executes on the Main thread when the target <see cref="Task"/> completes.
		/// </summary>
		/// <param name="continuationAction">
		/// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
		/// passed the completed task as an argument.
		/// </param>
		/// <returns>A new continuation <see cref="Task"/>.</returns>
		/// <remarks>
		/// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
		/// completed, whether it completes due to running to completion successfully, faulting due to an
		/// unhandled exception, or exiting out early due to being canceled.
		/// </remarks>
		/// <exception cref="T:System.ArgumentNullException">
		/// The <paramref name="continuationAction"/> argument is null.
		/// </exception>
        public Task ContinueInMainThreadWith(Action<Task> continuationAction)
        {
			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool> ();
			this.Wait ((t) => {
				Dispatcher.instance.ToMainThread(() =>
					{
						try
						{
							continuationAction(t);
							tcs.SetResult(true);
						}
						catch (Exception e)
						{
							tcs.SetError(e);
						}
					});
			});
			return tcs.Task;
        }
Example #4
0
        /// <summary>
        /// Creates a continuation that executes when the target <see cref="Task"/> completes.
        /// </summary>
        /// <param name="continuationAction">
        /// An action to run when the <see cref="Task"/> completes. When run, the delegate will be
        /// passed the completed task as an argument.
        /// </param>
        /// <returns>A new continuation <see cref="Task"/>.</returns>
        /// <remarks>
        /// The returned <see cref="Task"/> will not be scheduled for execution until the current task has
        /// completed, whether it completes due to running to completion successfully, faulting due to an
        /// unhandled exception, or exiting out early due to being canceled.
        /// </remarks>
        /// <exception cref="T:System.ArgumentNullException">
        /// The <paramref name="continuationAction"/> argument is null.
        /// </exception>
        public Task ContinueWith(Action<Task> continuationAction)
        {
			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool> ();
			this.Wait ((t) => {
				try
				{
					continuationAction(t);
					tcs.SetResult(true);
				}
				catch (Exception e)
				{
					tcs.SetError(e);
				}
			});
			return tcs.Task;
        }
    IEnumerator ConnectToAPI(int offset, TaskCompletionSource<bool> tcs, Action<int, string> intermediateResult)
    {
        yield return StartCoroutine(YOUR_FAVORITE_API_GetLeaderBoardUsingWWW (offset, queryLimit));

        SortedList<int, string> result = YOUR_FAVORITE_API_GetResultsFromCall ();

        if(result== null)
        {	// mockup an error in the API
            tcs.SetError(new Exception("API returns NULL"));
        }

        foreach(int k in result.Keys)
        {
            intermediateResult(k, result[k]);
        }
        if (result.Count == queryLimit)
        {
            GetCompleteLeaderboardAux(offset + queryLimit, tcs, intermediateResult);
        }
        else
        {
            tcs.SetResult(true);
        }
    }
 void GetCompleteLeaderboardAux(int offset, TaskCompletionSource<bool> tcs, Action<int, string> intermediateResult)
 {
     if (m_stopProcessing)
     {
         m_stopProcessing= false;
         tcs.SetError(new Exception("User cancelled"));
     }
     else
     {
         StartCoroutine(ConnectToAPI(offset, tcs, intermediateResult));
     }
 }