return taskCompletionSource.getTask();
return taskCompletionSource.getTask();
null, null); return tcs.getTask();
return tcs.getTask();
return allFinished.getTask();
return tcs.getTask();
FacebookRequestError error = response.getError(); if (error != null) { taskCompletionSource.setError(error.getException()); return; JSONObject responseJson = responseObject != null ? responseObject.getInnerJSONObject() : null; if (responseJson == null) { taskCompletionSource.setResult(appLinkResults); return; taskCompletionSource.setResult(appLinkResults);
@Override public Void then(final Task<T> task) throws Exception { if (task.isCancelled() && !reportCancellation) { tcs.setCancelled(); return null;
@Override public Void then(final Task<T> task) throws Exception { if (task.isCancelled() && !reportCancellation) { tcs.setCancelled(); return null;
@Override public void run() { try { Task<TContinuationResult> result = continuation.then(task); if (result == null) { tcs.setResult(null); } else { result.continueWith(new Continuation<TContinuationResult, Void>() { @Override public Void then(Task<TContinuationResult> task) { if (task.isCancelled()) { tcs.setCancelled(); } else if (task.isFaulted()) { tcs.setError(task.getError()); } else { tcs.setResult(task.getResult()); } return null; } }); } } catch (Exception e) { tcs.setError(e); } } });
/** * 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(); }
@Override public Void then(Task<Object> task) { if (task.isFaulted()) { synchronized (errorLock) { errors.add(task.getError()); } } if (task.isCancelled()) { isCancelled.set(true); } if (count.decrementAndGet() == 0) { if (errors.size() != 0) { if (errors.size() == 1) { allFinished.setError(errors.get(0)); } else { allFinished.setError(new AggregateException(errors)); } } else if (isCancelled.get()) { allFinished.setCancelled(); } else { allFinished.setResult(null); } } return null; } });
@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 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(); }
@Override public void onCancel() { tcs.trySetCancelled(); }