本文整理了Java中bolts.Task.continueWith()
方法的一些代码示例,展示了Task.continueWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.continueWith()
方法的具体详情如下:
包路径:bolts.Task
类名称:Task
方法名:continueWith
[英]Adds a synchronous continuation to this task, returning a new task that completes after the continuation has finished running.
[中]将同步延续添加到此任务,并返回一个新任务,该任务在延续完成运行后完成。
代码示例来源:origin: facebook/facebook-android-sdk
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();
}
}
};
代码示例来源:origin: parse-community/Parse-SDK-Android
/* 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;
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
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;
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* 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);
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
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;
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@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();
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@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");
}
});
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@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();
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* 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();
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@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();
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* 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.
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@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;
}
});
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@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;
}
});
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
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
代码示例来源:origin: parse-community/Parse-SDK-Android
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;
}
});
}
代码示例来源:origin: parse-community/Parse-SDK-Android
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) {
代码示例来源:origin: parse-community/Parse-SDK-Android
task.continueWith(new Continuation<T, Void>() {
@Override
public Void then(final Task<T> task) {
代码示例来源:origin: parse-community/Parse-SDK-Android
Task.whenAll(childTasks).continueWith(new Continuation<Void, Void>() {
@Override
public Void then(Task<Void> task) {
代码示例来源:origin: parse-community/Parse-SDK-Android
pin.put("command", command);
return pin.pinInBackground(PIN_NAME).continueWith(new Continuation<Void, EventuallyPin>() {
@Override
public EventuallyPin then(Task<Void> task) {
代码示例来源:origin: parse-community/Parse-SDK-Android
ParseUser.getCurrentUserAsync().makeVoid().continueWith(new Continuation<Void, Void>() {
@Override
public Void then(Task<Void> task) {
内容来源于网络,如有侵权,请联系作者删除!