本文整理了Java中bolts.Task.isCancelled()
方法的一些代码示例,展示了Task.isCancelled()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Task.isCancelled()
方法的具体详情如下:
包路径:bolts.Task
类名称:Task
方法名:isCancelled
暂无
代码示例来源:origin: facebook/facebook-android-sdk
@Suppress
public void testUrlWithNoAppLinkData() {
String testNoAppLinkUrlString = "https://fb.me/732873156764191_no_app_link";
Uri testNoAppLinkUrl = Uri.parse(testNoAppLinkUrlString);
try {
executeResolverOnBlockerThread(new FacebookAppLinkResolver(), testNoAppLinkUrl);
getTestBlocker().waitForSignals(1);
assertNotNull(resolveTask);
Task<AppLink> singleUrlResolveTask = (Task<AppLink>)resolveTask;
assertTrue(singleUrlResolveTask.isCompleted() &&
!singleUrlResolveTask.isCancelled() &&
!singleUrlResolveTask.isFaulted());
AppLink appLink = singleUrlResolveTask.getResult();
assertNull(appLink);
} catch (Exception e) {
// Forcing the test to fail with details
assertNull(e);
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> ignore) {
synchronized (tasksLock) {
// It might be better to return an aggregate error here.
for (Task<Void> task : tasks) {
if (task.isFaulted() || task.isCancelled()) {
return task;
}
}
tasks.clear();
return Task.forResult(null);
}
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> task) {
synchronized (mutex) {
if (task.isFaulted() || task.isCancelled()) {
removeAuthData(authType);
restoreAnonymity(oldAnonymousData);
return task;
}
return synchronizeAuthDataAsync(authType);
}
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Void then(final Task<T> task) {
if (task.isCancelled() && !reportCancellation) {
tcs.setCancelled();
return null;
}
ParseExecutors.main().execute(new Runnable() {
@Override
public void run() {
try {
Exception error = task.getError();
if (error != null && !(error instanceof ParseException)) {
error = new ParseException(error);
}
callback.done(task.getResult(), (ParseException) error);
} finally {
if (task.isCancelled()) {
tcs.setCancelled();
} else if (task.isFaulted()) {
tcs.setError(task.getError());
} else {
tcs.setResult(task.getResult());
}
}
}
});
return null;
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
private Task<File> fetchInBackground(
final ProgressCallback progressCallback,
Task<Void> toAwait,
final Task<Void> cancellationToken) {
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
}
return toAwait.continueWithTask(new Continuation<Void, Task<File>>() {
@Override
public Task<File> then(Task<Void> task) {
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
}
return getFileController().fetchAsync(
state,
null,
progressCallbackOnMainThread(progressCallback),
cancellationToken);
}
});
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<File> then(Task<Void> task) {
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
}
return getFileController().fetchAsync(
state,
null,
progressCallbackOnMainThread(progressCallback),
cancellationToken);
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
} else if (task.isCancelled()) {
throw new RuntimeException(new CancellationException());
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<JSONObject> then(Task<JSONObject> task) {
synchronized (taskQueueSyncLock) {
pendingEventuallyTasks.remove(uuid);
uuidToOperationSet.remove(uuid);
uuidToEventuallyPin.remove(uuid);
}
Exception error = task.getError();
if (error != null) {
tcs.trySetError(error);
} else if (task.isCancelled()) {
tcs.trySetCancelled();
} else {
tcs.trySetResult(task.getResult());
}
return tcs.getTask();
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
TaskCompletionSource<JSONObject> tcs;
if (task.isFaulted() || task.isCancelled()) {
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.forResult(null);
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncCancelled() throws Exception {
ParseFileController controller = mock(ParseFileController.class);
when(controller.isDataAvailable(any(ParseFile.State.class))).thenReturn(true);
ParseCorePlugins.getInstance().registerFileController(controller);
ParseFile.State state = new ParseFile.State.Builder().build();
ParseFile file = new ParseFile(state);
Task<Void> task = file.saveAsync(null, null, Task.<Void>cancelled());
task.waitForCompletion();
assertTrue(task.isCancelled());
verify(controller, never()).saveAsync(
any(ParseFile.State.class),
any(byte[].class),
any(String.class),
any(ProgressCallback.class),
Matchers.<Task<Void>>any());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncAlreadyCancelled() throws Exception {
ParseHttpClient restClient = mock(ParseHttpClient.class);
ParseFileController controller = new ParseFileController(restClient, null);
ParseFile.State state = new ParseFile.State.Builder().build();
Task<Void> cancellationToken = Task.cancelled();
Task<ParseFile.State> task = controller.saveAsync(state, (byte[]) null, null, null, cancellationToken);
task.waitForCompletion();
verify(restClient, times(0)).execute(any(ParseHttpRequest.class));
assertTrue(task.isCancelled());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
Exception e = task.getError();
if (task.isFaulted() && e instanceof ParseException) {
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testFetchAsyncAlreadyCancelled() throws Exception {
ParseHttpClient fileClient = mock(ParseHttpClient.class);
ParseFileController controller = new ParseFileController(null, null).fileClient(fileClient);
ParseFile.State state = new ParseFile.State.Builder().build();
Task<Void> cancellationToken = Task.cancelled();
Task<File> task = controller.fetchAsync(state, null, null, cancellationToken);
task.waitForCompletion();
verify(fileClient, times(0)).execute(any(ParseHttpRequest.class));
assertTrue(task.isCancelled());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Override
public Task<Void> then(Task<Void> task) {
if (task.isCancelled() || task.isFaulted()) { // Error
synchronized (user.mutex) {
if (oldUsername != null) {
user.setUsername(oldUsername);
} else {
user.revert(KEY_USERNAME);
}
if (oldPassword != null) {
user.setPassword(oldPassword);
} else {
user.revert(KEY_PASSWORD);
}
user.restoreAnonymity(anonymousData);
}
return task;
} else { // Success
user.revert(KEY_PASSWORD);
revert(KEY_PASSWORD);
}
mergeFromObject(user);
return saveCurrentUserAsync(ParseUser.this);
}
});
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testSaveAsyncNotDirty() throws Exception {
ParseHttpClient restClient = mock(ParseHttpClient.class);
ParseFileController controller = new ParseFileController(restClient, null);
ParseFile.State state = new ParseFile.State.Builder()
.url("http://example.com")
.build();
Task<ParseFile.State> task = controller.saveAsync(state, (byte[]) null, null, null, null);
task.waitForCompletion();
verify(restClient, times(0)).execute(any(ParseHttpRequest.class));
assertFalse(task.isFaulted());
assertFalse(task.isCancelled());
assertSame(state, task.getResult());
}
代码示例来源:origin: parse-community/Parse-SDK-Android
@Test
public void testCancel() {
ParseFile file = new ParseFile(new ParseFile.State.Builder().build());
TaskQueueTestHelper queueHelper = new TaskQueueTestHelper(file.taskQueue);
queueHelper.enqueue();
List<Task<Void>> saveTasks = Arrays.asList(
file.saveInBackground(),
file.saveInBackground(),
file.saveInBackground());
List<Task<byte[]>> getDataTasks = Arrays.asList(
file.getDataInBackground(),
file.getDataInBackground(),
file.getDataInBackground());
file.cancel();
queueHelper.dequeue();
for (int i = 0; i < saveTasks.size(); i++) {
assertTrue("Task #" + i + " was not cancelled", saveTasks.get(i).isCancelled());
}
for (int i = 0; i < getDataTasks.size(); i++) {
assertTrue("Task #" + i + " was not cancelled", getDataTasks.get(i).isCancelled());
}
}
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.forResult(null);
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.forResult(state);
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
代码示例来源:origin: parse-community/Parse-SDK-Android
return Task.forResult(state);
if (cancellationToken != null && cancellationToken.isCancelled()) {
return Task.cancelled();
内容来源于网络,如有侵权,请联系作者删除!