Skip to content

Commit

Permalink
fix: event emit once more when 'response' is comming of socketio engine.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangyufei49 committed Jul 19, 2018
1 parent fb681c1 commit 7139cbb
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions core/lib/engine_socketio.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,13 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
data: template(requestSpec.emit.data, context)
};

let endCallback = function (err, context) {
let endCallback = function (err, context, needEmit) {
if (err) {
debug(err);
}

if (isAcknowledgeRequired(requestSpec)) {
// Acknowledge required so add callback to emit
socketio.emit(outgoing.channel, outgoing.data, function () {
let ackCallback = function () {
let response = {
data: template(requestSpec.emit.acknowledge.data, context),
capture: template(requestSpec.emit.acknowledge.capture, context),
Expand All @@ -183,10 +182,19 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
}
return callback(err, context);
});
});
}

// Acknowledge required so add callback to emit
if (needEmit) {
socketio.emit(outgoing.channel, outgoing.data, ackCallback);
} else {
ackCallback();
}
} else {
// No acknowledge data is expected, so emit without a listener
socketio.emit(outgoing.channel, outgoing.data);
if (needEmit) {
socketio.emit(outgoing.channel, outgoing.data);
}
markEndTime(ee, context, startedAt);
return callback(null, context);
}
Expand All @@ -209,7 +217,7 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
}
// Stop listening on the response channel
socketio.off(response.channel);
return endCallback(err, context);
return endCallback(err, context, false);
});
});
// Send the data on the specified socket.io channel
Expand All @@ -225,7 +233,7 @@ SocketIoEngine.prototype.step = function (requestSpec, ee) {
}
}, waitTime);
} else {
endCallback(null, context);
endCallback(null, context, true);
}
};

Expand Down

0 comments on commit 7139cbb

Please sign in to comment.