[#ThreadPool-Submit-09a]
= xref:ThreadPool.adoc[ThreadPool]::Submit
:relfileprefix: ../
:mrdocs:

Enqueues a new task for asynchronous execution&period;

== Synopsis

Declared in `&lt;util&sol;threadpool&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;class F&gt;
&lsqb;&lsqb;nodiscard, requires&lowbar;capability(0x7f2e2046a3c8)&rsqb;&rsqb;
xref:util/Expected-0b.adoc[util::Expected&lt;Future&lt;F&gt;, SubmitError&gt;]
Submit(F&& fn) noexcept;
----

== Description

Thread&hyphen;safe&colon; Can be called from any thread, including within the provided &apos;fn&apos; callable&period;

[WARNING]
====
Ignoring the returned future requires guarding the task against uncaught exceptions, as they would otherwise be silently discarded&period;

====

== Return Value

On success, a future containing fn&apos;s result&period; On failure, an error indicating why the task was rejected&colon; &hyphen; SubmitError&colon;&colon;Inactive&colon; Pool has no workers (never started or already stopped)&period; &hyphen; SubmitError&colon;&colon;Interrupted&colon; Pool task acceptance has been interrupted&period;

[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&period;
|===


[.small]#Created with https://www.mrdocs.com[MrDocs]#
