Skip to content

The uWS::Loop::get()->defer method will block the reception of subsequent messages. How should this be handled? #1844

Description

@LetAmericaGreatAgain

play is a time-consuming task, and calling this method blocks the reception of subsequent messages. How should this be handled?

uWS::Loop::get()->defer([this, ws]() { 
    this->play(ws); 
});
app->ws<PerSocketData>(api, {
            .compression = uWS::DISABLED,
            .maxPayloadLength = 1024 * 1024 * 1024,
            .idleTimeout = 60,
            .maxBackpressure = 1024 * 1024 * 1024,
            .closeOnBackpressureLimit = false,
            .resetIdleTimeoutOnSend = true,
            .sendPingsAutomatically = true,
            .upgrade = nullptr,
            .open = [](uWS::WebSocket<false, true, PerSocketData> *ws) {
                std::cout << "open..." << std::endl;
            },
            .message = [this](uWS::WebSocket<false, true, PerSocketData> *ws, std::string_view message,
                              uWS::OpCode opCode) {
                try {
                    IMMsg msg = json::parse(message);
                    if(msg.getType() == "Video") {
                        std::string cmd = msg.getCmd();
                        if(cmd == "play") {
                            uWS::Loop::get()->defer([this, ws]() {
                                this->play(ws);
                            });
                        } else if(cmd == "stop") {
                            this->stop();
                        }
                    }
                } catch (json::exception &e) {
                    LOGI << "Parsing message exception..." << e.what();
                }

            },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions