这段代码是asynchronous执行的吗?

我正在学习Node.js,并且已经理解了asynchronous函数调用的概念。 但现在我有一个新的难题。

我有一些看起来像这样的代码(你不必详细阅读,这只是一个摘录来说明我的问题):

var seat_winner = states[gid].current_trick[trick_winner].seat;console.log(seat_winner+" won "+trick_pts+" points"); states[gid][seat_winner].points += trick_pts; if(states[gid][seat_winner].team == "blue"){ states[gid].points_blue += trick_pts; states[gid].points_blue_total += trick_pts; } else{ states[gid].points_red += trick_pts; states[gid].points_red_total += trick_pts; } states[gid].current_trick = { 1: {seat: 0, card: "N"}, 2: {seat: 0, card: "N"}, 3: {seat: 0, card: "N"}, 4: {seat: 0, card: "N"} }; states[gid].trick_in_progress++; var score = [states[gid].points_blue, states[gid].points_red, states[gid].points_blue_total, states[gid].points_red_total, states[gid].game40holder, states[gid].trump]; io.sockets.in(room).emit('score', score); //also tell the client to clean up the display for the next trick io.sockets.in(room).emit('cleanUp', null); next++; if(next > 4) next -= 4; states[gid].next_to_play = next; states[gid].current_trick[order_to_play] = { "seat": seat, "card": states[gid][seat].hand[to_play] }; states[gid].played_cards.push(states[gid][seat].hand[to_play]); states[gid][seat].hand[to_play] = "N"; nextMove(gid); 

这里没有函数调用,除了最后的nextMove()函数。 但是我在客户端上得到了一些奇怪的结果,就像上面的代码完全asynchronous执行一样。 但是这没有意义,是吗? 上述是否有任何理由asynchronous执行?

我看不到上面的代码中指定的任何callback函数。

只有你的代码中的代码是为你创build问题的是以下几行。

  io.sockets.in(room).emit('score', score); //also tell the client to clean up the display for the next trick io.sockets.in(room).emit('cleanUp', null); 

当第一个发射发生,紧接着,第二个发射发生..也许这不是你想要的..也许你想要做第二个发射时,第一个发射完成!

编辑:所以你可以说上面的行是asynchronous的,因为第二个发射甚至在第一个发射完全之前被发射。