Executes the request. This will automatically retry if we hit a ratelimit.

@param function A function which processes the rest response to the requested object.
@return A future which will contain the output of the function.
481257
public CompletableFuture<T> execute(Function<RestRequestResult, T> function) {
        api.getRatelimitManager().queueRequest(this);
        CompletableFuture<T> future = new CompletableFuture<>();
        result.whenComplete((result, throwable) -> {
            if (throwable != null) {
                future.completeExceptionally(throwable);
                return;
            }
            try {
                future.complete(function.apply(result));
            } catch (Throwable t) {
                future.completeExceptionally(t);
            }
        });
        return future;
    }
803543
protected <T> T invokeJavascriptReturnValue(String function, Class<T> returnType) {
        Object returnObject = invokeJavascript(function);
        if (returnObject instanceof JSObject) {
            try {
                Constructor<T> constructor = returnType.getConstructor(JSObject.class);
                return constructor.newInstance((JSObject) returnObject);
            } catch (Exception ex) {
                throw new IllegalStateException(ex);
            }
        } else {
            return (T) returnObject;
        }
    }
803264
public <T> CompletableFuture<T> submit(Query<T> query) {
    CompletableFuture<T> future = new CompletableFuture<>();
    context.executor().execute(() -> submitQuery(query, future));
    return future;
  }
823697
private <R> Future<R> scheduleAsync(Callable<R> func) {
        return executor.submit(func);
    }
688338
public static void executeAsync(Executor executor, HttpRequestBase request, FutureCallback<HttpResponse> callback) {

		try {
			executor.execute(new AsyncHttpCall(request, callback));
		}
		catch (Exception e) {
			log.error("Failed to execute asynchronously: " + request.getMethod() + " " + request.getURI().toString());
		}
	}
1333379
private <T> Func1<List<Parameter>, Observable<T>> executeOnce(
            final ResultSetMapper<? extends T> function) {
        return new Func1<List<Parameter>, Observable<T>>() {
            @Override
            public Observable<T> call(List<Parameter> params) {
                return executeOnce(params, function);
            }
        };
    }
27941
public static <T> Future<T> submit(Callable<T> task) {
		return executor.submit(task);
	}
1031679
@SuppressWarnings("unchecked")
  public static <T> ComposableFuture<T> retry(final int retries, final Function<Integer, ComposableFuture<T>> producer) {
    final BiFunction<BiFunction, Integer, ComposableFuture<T>> retriable = (f, attempt) ->
      Try.apply(() -> producer.apply(attempt)).
        recover(ComposableFutures::fromError).
        map(action -> action.recoverWith(error -> {
            if (attempt >= retries) {
              return fromError(error);
            }

            // we can't safely use generics here since we'll get into infinite nested generics
            return (ComposableFuture<T>) f.apply(f, attempt + 1);
          })
        ).getValue();

    return retriable.apply(retriable, 0);
  }
91185
public static void run(StreamFunctionExecutor functionExecutor, String... args) {
        parseData(args, (data, isDebug) -> {
            try (InputStream input = data != null ? new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8)) : System.in) {
                functionExecutor.execute(input, System.out);
            } catch (Exception e) {
                exitWithError(isDebug, e);
            }
        });
    }
216275
public <T> T execute(final Callable<T> callable) throws Exception {
        int attempts = 0;
        int maxAttempts = retryPolicy.getMaxAttempts();
        long delay = retryPolicy.getDelay();
        TimeUnit timeUnit = retryPolicy.getTimeUnit();
        while(attempts < maxAttempts) {
            try {
                attempts++;
                beforeCall();
                T result = callable.call();
                afterCall(result);
                return result;
            } catch (Exception e) {
                onException(e);
                if (attempts >= maxAttempts) {
                    onMaxAttempts(e);
                    throw e;
                }
                beforeWait();
                sleep(timeUnit.toMillis(delay));
                afterWait();
            }
        }
        return null;
    }
1182158
public function processRequest($function = null)
    {
        if ($function) {
            $this->$function();
            $this->dispatchEvent(new AfterRequestProcessedEvent);
        } else {
            $sQAdd = $this->_getQuery();

            // formatting SQL queries
            $sQ = $this->_getDataQuery($sQAdd);
            $sCountQ = $this->_getCountQuery($sQAdd);

            $this->_outputResponse($this->_getData($sCountQ, $sQ));
        }
    }
914736
async def _execute(self, fn, *args, **kwargs):
        """"""
        function = partial(fn, *args, **kwargs)
        future = self._loop.create_future()

        self._tx.put_nowait((future, function))

        return await future
309880
@SuppressWarnings("unchecked")
  private void handleResponseSuccess(long requestId, Object response) {
    ContextualFuture future = responseFutures.remove(requestId);
    if (future != null) {
      future.context.executor().execute(() -> future.complete(response));
    }
  }
476705
public static <T, R> Function<T, R> wrap(final Function<T, R> function)
	{
		final Tracing tracing = Tracing.get();

		final String traceId = tracing.newOperationId();
		return wrap(traceId, tracing.isVerbose(), function);
	}
711910
@Beta
  public Future<HttpResponse> executeAsync(Executor executor) {
    FutureTask<HttpResponse> future =
        new FutureTask<HttpResponse>(
            new Callable<HttpResponse>() {

              public HttpResponse call() throws Exception {
                return execute();
              }
            });
    executor.execute(future);
    return future;
  }
175024
@SneakyThrows
    public static <T, R> Function<T, R> doAndHandle(final CheckedFunction<T, R> function, final CheckedFunction<Throwable, R> errorHandler) {
        return t -> {
            try {
                return function.apply(t);
            } catch (final Throwable e) {
                LOGGER.warn(e.getMessage(), e);
                try {
                    return errorHandler.apply(e);
                } catch (final Throwable ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }
        };
    }
421860
@Override
    public <R> Future<R> map(final Function<? super T, ? extends R> fn) {
        return new Future<R>(
                              future.thenApply(fn));
    }