Nodejs requests come in. I put the requests in the queue. How can I take them out one by one?

use scoket to do chat program, request in, and I put the request in the queue. The code is as follows:

  rob_vest: async function (data, socket, io) {
        console.log(type, "------------------------------------------")
        var queue = new Queue();//
        queue.push(data)//
        get_vetst(queue,socket, io)//


    },
async function get_vetst(queue,socket, io) {
    // let sequlize = await db
    let len = queue.size()
    if (len !== 0) {
        let data = queue.pop() //
        //
        ...
        }
    }

I would like to write that if the next request depends on the result of the previous operation table, it will lead to unexpected results. Although it is put into the queue, if two requests come in at the same time, the data in the column will be read at the same time, and then the table will be manipulated at the same time. As a result, the second request will not get the first result. The ideal process is that two requests will come in. Put two requests into the queue, and then trigger a method that reads the data in the queue. After reading and performing a series of operations for the first time, the
get_vetst method should not rely on rob_vest
what should I do? Ladies and gentlemen,

Jun.08,2021

requires callback to send back ack confirmation messages. Refer to the message confirmation mechanism of amqp protocol


what you should worry about is the data update in the case of concurrency. It is recommended that you understand the locks related to the database, such as pessimistic locks, optimistic locks, transactions, etc.

Menu