Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Commit

Permalink
Make JavaScript HttpConnection emit timeout event (#3)
Browse files Browse the repository at this point in the history
The JavaScript `HttpConnection` allows the caller to set a request timeout via the `nodeOptions` property. However, neither the HTTP connection nor the thrift client provides a way for the caller to know when a timeout occured. With this change, the `HttpConnection` will now emit a timeout event when the NodeJS timeout event occurs. A caller can add an event listener to the connection as follows:

```
const thrift = require('thrift');
const connection = thrift.createHttpConnection('localhost', 1234, {
  nodeOptions: {
    timeout: 1000
  }
});
connection.on();
connection.on('timeout', () => {
  console.log('Request timed out after 1000ms');
});
```
  • Loading branch information
alaynarichmond authored Mar 14, 2022
1 parent 24d1da8 commit 0c78794
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/nodejs/lib/thrift/http_connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ HttpConnection.prototype.write = function(data) {
req.on('error', function(err) {
self.emit("error", err);
});
req.on('timeout', function(err) {
self.emit("timeout", err);
});
req.write(data);
req.end();
};
Expand Down

0 comments on commit 0c78794

Please sign in to comment.