@Override
    public boolean cancel(boolean mayInterruptIfRunning) {
        synchronized (this) {
            if (isDone()) {
                return false;
            }
            if (mayInterruptIfRunning) {
                this.cancelled = true;
                finishedLatch.countDown();
                return true;
            }
        }
        try {
            finishedLatch.await();
        } catch (InterruptedException e) {
            throw new ConnectException("Interrupted while waiting for task to complete", e);
        }
        return false;
    }
@Test
    public void shouldCancelBeforeGetIfMayCancelWhileRunning() {
        TestConvertingFutureCallback testCallback = new TestConvertingFutureCallback();
        assertTrue(testCallback.cancel(true));
        assertThrows(CancellationException.class, testCallback::get);
    }