[#ThreadPool-Submit-09b] = xref:ThreadPool.adoc[ThreadPool]::Submit :relfileprefix: ../ :mrdocs: Enqueues a range of tasks for asynchronous execution. == Synopsis Declared in `<util/threadpool.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<std::ranges::sized_range R> requires (!std::is_lvalue_reference_v<R>) [[nodiscard, requires_capability(0x7f2e2046a4d8)]] xref:util/Expected-0b.adoc[util::Expected<std::vector<RangeFuture<R>>, SubmitError>] Submit(R&& fns) noexcept; ---- == Description This is more efficient when submitting many tasks at once, since the queue lock is only taken once internally and all worker threads are notified. For single tasks, Submit() is preferred since only one worker thread is notified. Thread‐safe: Can be called from any thread, including within submitted callables. [WARNING] ==== Ignoring the returned futures requires guarding tasks against uncaught exceptions, as they would otherwise be silently discarded. ==== == Return Value On success, a vector of futures containing each element of fns's result in order. On failure, an error indicating why the range was rejected: ‐ SubmitError::Inactive: Pool has no workers (never started or already stopped). ‐ SubmitError::Interrupted: Pool task acceptance has been interrupted. [NOTE] ==== The return value https://en.cppreference.com/cpp/language/attributes/nodiscard[should not be discarded^]. ==== == Parameters [cols="1,4"] |=== | Name| Description | *fns* | Callables to execute asynchronously. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#