class DirectPollingFuture<S> implements Future<S> {

		private final long startTime = System.currentTimeMillis();

		private volatile boolean cancelled;

		private volatile S result = null;

		private final long interval;

		private final Callable<S> callable;

		public DirectPollingFuture(long interval, Callable<S> callable) {
			this.interval = interval;
			this.callable = callable;
		}

		@Override
		public boolean cancel(boolean mayInterruptIfRunning) {
			cancelled = true;
			return true;
		}

		@Override
		public S get() throws InterruptedException, ExecutionException {
			try {
				return get(-1, TimeUnit.MILLISECONDS);
			}
			catch (TimeoutException e) {
				throw new IllegalStateException("Unexpected timeout waiting for result", e);
			}
		}

		@Override
		public S get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {<FILL_FUNCTION_BODY>}

		@Override
		public boolean isCancelled() {
			return cancelled;
		}

		@Override
		public boolean isDone() {
			return cancelled || result != null;
		}

	}


			try {
				result = callable.call();
			}
			catch (Exception e) {
				throw new ExecutionException(e);
			}

			long nextExecutionTime = startTime + interval;
			long currentTimeMillis = System.currentTimeMillis();
			long timeoutMillis = TimeUnit.MILLISECONDS.convert(timeout, unit);

			while (result == null && !cancelled) {

				long delta = nextExecutionTime - startTime;
				if (delta >= timeoutMillis && timeoutMillis > 0) {
					throw new TimeoutException("Timed out waiting for task to return non-null result");
				}

				if (nextExecutionTime > currentTimeMillis) {
					Thread.sleep(nextExecutionTime - currentTimeMillis);
				}

				currentTimeMillis = System.currentTimeMillis();
				nextExecutionTime = currentTimeMillis + interval;

				try {
					result = callable.call();
				}
				catch (Exception e) {
					throw new ExecutionException(e);
				}

			}

			return result;

		
<no_super_class>