final Task<Map<Uri, AppLink>>.TaskCompletionSource taskCompletionSource = Task.create();
/** * 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 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(); }
/** * Creates a cancelled task. */ public static <TResult> Task<TResult> cancelled() { Task<TResult>.TaskCompletionSource tcs = Task.<TResult> create(); tcs.setCancelled(); 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(); }
final Task<Void>.TaskCompletionSource allFinished = Task.<Void> create(); final ArrayList<Exception> errors = new ArrayList<Exception>(); final Object errorLock = new Object();
/** * 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(); }
final Task<Map<Uri, AppLink>>.TaskCompletionSource taskCompletionSource = Task.create();
/** * 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(); }
return task; final Task<T>.TaskCompletionSource tcs = Task.create(); task.continueWith(new Continuation<T, Void>() { @Override
@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(); }
return task; final Task<T>.TaskCompletionSource tcs = Task.create(); task.continueWith(new Continuation<T, Void>() { @Override
@Override public Task<JSONArray> then(Task<Void> task) throws Exception { final Task<JSONArray>.TaskCompletionSource tcs = Task.create(); final WebView webView = new WebView(context); webView.getSettings().setJavaScriptEnabled(true);
public synchronized Task<Map<String, String>> authenticateAsync() { Task<Map<String, String>>.TaskCompletionSource tcs = Task.create(); if (currentTcs != null) { handleCancel();
final Task<Map<String, String>>.TaskCompletionSource tcs = Task.create(); LoginManager manager = facebookSdkDelegate.getLoginManager();