[英]Order of data and end event of http.createServer
const server = http.createServer(async (request, response) => {
if (request.method === "POST") {
var data = "";
request
.on("data", async (chunk) => {
console.log("1");
data += chunk;
console.log("2");
await connection.query({sql query});
console.log("3");
})
.on("end", async () => {
console.log("4");
});
}
}
結果如下
1 4 2 3
你知道如何同步處理並使結果順序為 1 2 3 4 嗎?
如果要同步添加,為什么要添加 async 關鍵字。 此外,我最好將 go 與現代服務器一起使用,並為此使用快遞 package。 使用此鏈接: https://expressjs.com/en/starter/hello-world.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.