def gather_any(threadpool: ThreadPool, func: Callable, params: Iterable, *args: Any, **kwargs: Any) -> Tuple[Any, Any]: """Runs multiple tasks concurrently and just returns the result of the first task which finishes. """ for id, result in gather_all_unsorted(threadpool, func, params, *args, **kwargs): threadpool.cancel() return id, result # result will be None, if tasked threw exception raise NoResult("No task returned a valid result")