Skip to content

Commit

Permalink
refactor: refactor SENT_CLIENT_REQUEST state
Browse files Browse the repository at this point in the history
  • Loading branch information
mShan0 committed May 16, 2022
1 parent efefd51 commit 41d99bf
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/connection.ts
Expand Up @@ -3598,26 +3598,15 @@ Connection.prototype.STATE = {
SENT_CLIENT_REQUEST: {
name: 'SentClientRequest',
enter: function() {
this.emptyMessageBuffer();

this.messageIo.readMessage().then((message) => {
this.dispatchEvent('message', message);
}, (err) => {
this.socketError(err);
});
},
exit: function(nextState) {
this.clearRequestTimer();
},
events: {
socketError: function(err) {
const sqlRequest = this.request!;
this.request = undefined;
this.transitionTo(this.STATE.FINAL);
(async () => {
this.emptyMessageBuffer();

sqlRequest.callback(err);
},
message: function(message) {
let message;
try {
message = await this.messageIo.readMessage();
} catch (err: any) {
return this.socketError(err);
}
// request timer is stopped on first data package
this.clearRequestTimer();

Expand Down Expand Up @@ -3685,6 +3674,19 @@ Connection.prototype.STATE = {

tokenStreamParser.once('end', onEndOfMessage);
this.request?.once('cancel', onCancel);
})();

},
exit: function(nextState) {
this.clearRequestTimer();
},
events: {
socketError: function(err) {
const sqlRequest = this.request!;
this.request = undefined;
this.transitionTo(this.STATE.FINAL);

sqlRequest.callback(err);
}
}
},
Expand Down

0 comments on commit 41d99bf

Please sign in to comment.