@Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast();
@Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast();
@Override public Task<Void> then(Task<Void> task) { if (cancelled.get()) { return Task.cancelled(); } return task; } })).cast();
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); } }); }
@Override public Task<File> then(Task<Void> task) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled(); } return getFileController().fetchAsync( state, null, progressCallbackOnMainThread(progressCallback), cancellationToken); } });
final Task<Void> cancellationToken) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled();
return Task.cancelled();
@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()); }
@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()); }
@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()); }
if (task.isFaulted() && e instanceof ParseException) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled();
final Task<Void> cancellationToken) { if (cancellationToken != null && cancellationToken.isCancelled()) { return Task.cancelled();
return Task.cancelled();
@Override public Task<List<T>> then(Task<List<T>> task) throws Exception { if (ct != null && ct.isCancellationRequested()) { return Task.cancelled(); } return task; } });
return Task.cancelled();
return Task.cancelled();
@Override public Task<Void> resetAsync() { EventImpl event = (EventImpl) mwPrivate.getModules().get(EventImpl.class); Task<Void> task= (event != null && event.activeDataType != null) ? Task.cancelled() : mwPrivate.boardDisconnect(); mwPrivate.sendCommand(new byte[] {DEBUG.id, 0x1}); return task; }
@Override public Task<Void> disconnectAsync() { EventImpl event = (EventImpl) mwPrivate.getModules().get(EventImpl.class); Task<Void> task= (event != null && event.activeDataType != null) ? Task.cancelled() : mwPrivate.boardDisconnect(); mwPrivate.sendCommand(new byte[] {DEBUG.id, 0x6}); return task; }
@Override public Task<Void> jumpToBootloaderAsync() { EventImpl event = (EventImpl) mwPrivate.getModules().get(EventImpl.class); Task<Void> task= (event != null && event.activeDataType != null) ? Task.cancelled() : mwPrivate.boardDisconnect(); mwPrivate.sendCommand(new byte[] {DEBUG.id, 0x2}); return task; }
@Override public Task<Void> then(Task<TResult> task) throws Exception { if (task.isCancelled()) { return Task.cancelled(); } if (task.isFaulted()) { return Task.forError(task.getError()); } return Task.forResult(null); } });