Function Reactor.deferToThread

run a function inside a different thread.

auto auto deferToThread(alias F, alias Fini) (
  Parameters!F args,
  Timeout timeout = Timeout.infinite
) @nogc;

auto auto deferToThread(F) (
  scope F dlg,
  Timeout timeout = Timeout.infinite
) @nogc;

Runs a function inside a thread. Use this function to run CPU bound processing without freezing the other fibers.

Fini, if provided, will be called with the same parameters in the reactor thread once the thread has finished. Fini will be called unconditionally, even if the fiber that launched the thread terminates before the thread has finished.

The Fini function runs within a criticalSection, and must not sleep.

Returns

The return argument from the delegate is returned by this function.

Throws

Will throw TimeoutExpired if the timeout expires.

Will rethrow whatever the thread throws in the waiting fiber.