[#ThreadPool-Submit-09a] = xref:ThreadPool.adoc[ThreadPool]::Submit :relfileprefix: ../ :mrdocs: Enqueues a new task for asynchronous execution. == Synopsis Declared in `<util/threadpool.h>` [source,cpp,subs="verbatim,replacements,macros,-callouts"] ---- template<class F> [[nodiscard, requires_capability(0x7f2e2046a3c8)]] xref:util/Expected-0b.adoc[util::Expected<Future<F>, SubmitError>] Submit(F&& fn) noexcept; ---- == Description Thread‐safe: Can be called from any thread, including within the provided 'fn' callable. [WARNING] ==== Ignoring the returned future requires guarding the task against uncaught exceptions, as they would otherwise be silently discarded. ==== == Return Value On success, a future containing fn's result. On failure, an error indicating why the task 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 | *fn* | Callable to execute asynchronously. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#