return taskCompletionSource.getTask();
return taskCompletionSource.getTask();
return allFinished.getTask();
null, null); return tcs.getTask();
return tcs.getTask();
return tcs.getTask();
@Deprecated public synchronized Task<Map<String, String>> extendAccessToken(Context context) { Task<Map<String, String>>.TaskCompletionSource tcs = Task.create(); if (currentTcs != null) { handleCancel(); } currentTcs = tcs; boolean result = facebook.extendAccessToken(context, new ServiceListener() { @Override public void onComplete(Bundle values) { handleSuccess(userId); } @Override public void onFacebookError(FacebookError e) { handleError(e); } @Override public void onError(Error e) { handleError(new ParseException(e)); } }); if (!result) { handleCancel(); } return tcs.getTask(); }
/** * Adds an Task-based continuation to this task that will be scheduled using the executor, * returning a new task that completes after the task returned by the continuation has completed. */ public <TContinuationResult> Task<TContinuationResult> continueWithTask( final Continuation<TResult, Task<TContinuationResult>> continuation, final Executor executor) { boolean completed = false; final Task<TContinuationResult>.TaskCompletionSource tcs = Task.<TContinuationResult> create(); synchronized (lock) { completed = this.isCompleted(); if (!completed) { this.continuations.add(new Continuation<TResult, Void>() { @Override public Void then(Task<TResult> task) { completeAfterTask(tcs, continuation, task, executor); return null; } }); } } if (completed) { completeAfterTask(tcs, continuation, this, executor); } return tcs.getTask(); }
/** * Adds a continuation that will be scheduled using the executor, returning a new task that * completes after the continuation has finished running. This allows the continuation to be * scheduled on different thread. */ public <TContinuationResult> Task<TContinuationResult> continueWith( final Continuation<TResult, TContinuationResult> continuation, final Executor executor) { boolean completed = false; final Task<TContinuationResult>.TaskCompletionSource tcs = Task.<TContinuationResult> create(); synchronized (lock) { completed = this.isCompleted(); if (!completed) { this.continuations.add(new Continuation<TResult, Void>() { @Override public Void then(Task<TResult> task) { completeImmediately(tcs, continuation, task, executor); return null; } }); } } if (completed) { completeImmediately(tcs, continuation, this, executor); } return tcs.getTask(); }
/** * Invokes the callable using the given executor, returning a Task to represent the operation. */ public static <TResult> Task<TResult> call(final Callable<TResult> callable, Executor executor) { final Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); executor.execute(new Runnable() { @Override public void run() { try { tcs.setResult(callable.call()); } catch (Exception e) { tcs.setError(e); } } }); return tcs.getTask(); }
/** * Creates a completed task with the given value. */ public static <TResult> Task<TResult> forResult(TResult value) { Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); tcs.setResult(value); return tcs.getTask(); }
/** * Creates a cancelled task. */ public static <TResult> Task<TResult> cancelled() { Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); tcs.setCancelled(); return tcs.getTask(); }
/** * Creates a faulted task with the given error. */ public static <TResult> Task<TResult> forError(Exception error) { Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); tcs.setError(error); return tcs.getTask(); }