public void run() { try { resolveTask = resolver.getAppLinkFromUrlInBackground(testUrl); resolveTask.continueWith(new Continuation() { @Override public Object then(Task task) throws Exception { // Once the task is complete, unblock the test thread, so it can inspect for errors/results. blocker.signal(); return null; } }); } catch (Exception e) { // Get back to the test case if there was an uncaught exception blocker.signal(); } } };
/* package */ Task<Void> open(final SQLiteOpenHelper helper) { synchronized (currentLock) { current = current.continueWith(new Continuation<Void, SQLiteDatabase>() { @Override public SQLiteDatabase then(Task<Void> task) { // get*Database() is synchronous and calls through SQLiteOpenHelper#onCreate, onUpdate, // etc. return (openFlags & SQLiteDatabase.OPEN_READONLY) == SQLiteDatabase.OPEN_READONLY ? helper.getReadableDatabase() : helper.getWritableDatabase(); } }, dbExecutor).continueWithTask(new Continuation<SQLiteDatabase, Task<Void>>() { @Override public Task<Void> then(Task<SQLiteDatabase> task) { db = task.getResult(); return task.makeVoid(); } }, Task.BACKGROUND_EXECUTOR); // We want to jump off the dbExecutor return current; } }
public Task<Boolean> isReadOnlyAsync() { synchronized (currentLock) { Task<Boolean> task = current.continueWith(new Continuation<Void, Boolean>() { @Override public Boolean then(Task<Void> task) { return db.isReadOnly(); } }); current = task.makeVoid(); return task; } }
/** * Ends a transaction. * * @see SQLiteDatabase#endTransaction */ public Task<Void> endTransactionAsync() { synchronized (currentLock) { current = current.continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { db.endTransaction(); // We want to swallow any exceptions from our Session task return null; } }, dbExecutor); return current.continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { // We want to jump off the dbExecutor return task; } }, Task.BACKGROUND_EXECUTOR); } }
public Task<Boolean> isOpenAsync() { synchronized (currentLock) { Task<Boolean> task = current.continueWith(new Continuation<Void, Boolean>() { @Override public Boolean then(Task<Void> task) { return db.isOpen(); } }); current = task.makeVoid(); return task; } }
@Override public <T extends ParseObject> Task<Integer> countAsync(ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) { final AtomicBoolean cancelled = new AtomicBoolean(false); cancellationToken.continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { cancelled.set(true); return null; } }); return await(Task.<Void>forResult(null).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast(); }
@Override public <T extends ParseObject> Task<T> getFirstAsync(ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) { return findAsync(state, user, cancellationToken).continueWith(new Continuation<List<T>, T>() { @Override public T then(Task<List<T>> task) throws Exception { if (task.isFaulted()) { throw task.getError(); } if (task.getResult() != null && task.getResult().size() > 0) { return task.getResult().get(0); } throw new ParseException(ParseException.OBJECT_NOT_FOUND, "no results found for query"); } }); } }
@Override public <T extends ParseObject> Task<T> getFirstAsync(ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) { final AtomicBoolean cancelled = new AtomicBoolean(false); cancellationToken.continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { cancelled.set(true); return null; } }); return await(Task.<Void>forResult(null).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast(); } }
/** * Gets a task that can be safely awaited and is dependent on the current tail of the queue. This * essentially gives us a proxy for the tail end of the queue that can be safely cancelled. * * @return A new task that should be awaited by enqueued tasks. */ private Task<Void> getTaskToAwait() { lock.lock(); try { Task<Void> toAwait = tail != null ? tail : Task.<Void>forResult(null); return toAwait.continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { return null; } }); } finally { lock.unlock(); } }
@Override public <T extends ParseObject> Task<List<T>> findAsync(ParseQuery.State<T> state, ParseUser user, Task<Void> cancellationToken) { final AtomicBoolean cancelled = new AtomicBoolean(false); cancellationToken.continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { cancelled.set(true); return null; } }); return await(Task.<Void>forResult(null).continueWithTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast(); }
/** * This is kind of like ParseTaskUtils.wait(), except that it gives up the CommandCache's lock * while the task is running, and reclaims it before returning. */ private <T> T waitForTaskWithoutLock(Task<T> task) throws ParseException { synchronized (lock) { final Capture<Boolean> finished = new Capture<>(false); task.continueWith(new Continuation<T, Void>() { @Override public Void then(Task<T> task) { finished.set(true); synchronized (lock) { lock.notifyAll(); } return null; } }, Task.BACKGROUND_EXECUTOR); while (!finished.get()) { try { lock.wait(); } catch (InterruptedException ie) { shouldStop = true; } } return ParseTaskUtils.wait(task); // Just to get the return value and maybe rethrow. } }
@Override public Task<T> then(Task<T> task) { final T object = task.getResult(); if (object == null) { return task; } return Task.whenAll(Arrays.asList( from.deleteAsync(), to.setAsync(object) )).continueWith(new Continuation<Void, T>() { @Override public T then(Task<Void> task) { return object; } }); } });
@Override public Task<ParseConfig> then(Task<JSONObject> task) { JSONObject result = task.getResult(); final ParseConfig config = ParseConfig.decode(result, ParseDecoder.get()); return currentConfigController.setCurrentConfigAsync(config).continueWith(new Continuation<Void, ParseConfig>() { @Override public ParseConfig then(Task<Void> task) { return config; } }); } });
values.put(OfflineSQLiteOpenHelper.KEY_UUID, newUUID); values.put(OfflineSQLiteOpenHelper.KEY_CLASS_NAME, object.getClassName()); db.insertOrThrowAsync(OfflineSQLiteOpenHelper.TABLE_OBJECTS, values).continueWith( new Continuation<Void, Void>() { @Override
private Task<Void> deleteAsync(final String sessionToken, Task<Void> toAwait) { validateDelete(); return toAwait.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { isDeleting = true; if (state.objectId() == null) { return task.cast(); // no reason to call delete since it doesn't exist } return deleteAsync(sessionToken); } }).onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return handleDeleteResultAsync(); } }).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) throws Exception { isDeleting = false; if (task.isFaulted()) { throw task.getError(); } return null; } }); }
tasks.add(file.saveAsync(sessionToken, null, null)); Task<Void> filesTask = Task.whenAll(tasks).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) { tasks.add(user.saveAsync(sessionToken)); Task<Void> usersTask = Task.whenAll(tasks).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) {
task.continueWith(new Continuation<T, Void>() { @Override public Void then(final Task<T> task) {
Task.whenAll(childTasks).continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) {
pin.put("command", command); return pin.pinInBackground(PIN_NAME).continueWith(new Continuation<Void, EventuallyPin>() { @Override public EventuallyPin then(Task<Void> task) {
ParseUser.getCurrentUserAsync().makeVoid().continueWith(new Continuation<Void, Void>() { @Override public Void then(Task<Void> task) {