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

Enqueues a range of tasks for asynchronous execution&period;

== Synopsis

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

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
template&lt;std::ranges::sized&lowbar;range R&gt;
requires (!std&colon;&colon;is&lowbar;lvalue&lowbar;reference&lowbar;v&lt;R&gt;)
&lsqb;&lsqb;nodiscard, requires&lowbar;capability(0x7f951f99b4f8)&rsqb;&rsqb;
xref:util/Expected-0b.adoc[util::Expected&lt;std::vector&lt;RangeFuture&lt;R&gt;&gt;, SubmitError&gt;]
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&period; For single tasks, Submit() is preferred since only one worker thread is notified&period;

Thread&hyphen;safe&colon; Can be called from any thread, including within submitted callables&period;

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

====

== Return Value

On success, a vector of futures containing each element of fns&apos;s result in order&period; On failure, an error indicating why the range 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
| *fns*
| Callables to execute asynchronously&period;
|===


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