ThreadPool::Submit

Enqueues a new task for asynchronous execution.

Synopsis

Declared in <util/threadpool.h>

template<class F>
[[nodiscard, requires_capability(0x7f2e2046a3c8)]]
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 should not be discarded.

Parameters

NameDescription
fnCallable to execute asynchronously.