Class WorkReq

Synopsis

#include <src/uvw/work.h>

class WorkReq final: public Request<WorkReq, uv_work_t>

Description

The WorkReq request.

It runs user code using a thread from the threadpool and gets notified in the loop thread by means of an event.

To create a WorkReq through a Loop, arguments follow:

  • A valid instance of a Task, that is of type std::function<void(void)>.

See the official documentation for further details.

Inheritance

Ancestors: Request

Methods

WorkReq
queueRuns the given task in a separate thread.

Source

Lines 37-58 in src/uvw/work.h.

class WorkReq final: public Request<WorkReq, uv_work_t> {
    using InternalTask = std::function<void(void)>;

    static void workCallback(uv_work_t *req);

public:
    using Task = InternalTask;

    explicit WorkReq(ConstructorAccess ca, std::shared_ptr<Loop> ref, InternalTask t);

    /**
     * @brief Runs the given task in a separate thread.
     *
     * A WorkEvent event will be emitted on the loop thread when the task is
     * finished.<br/>
     * This request can be cancelled with `cancel()`.
     */
    void queue();

private:
    Task task{};
};





Add Discussion as Guest

Log in