Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

use http api of node v6.x (fixes #33)

  • Loading branch information...
commit 5feb65c1d91cb6240a681f76b1aa2dcfb23c2e12 1 parent 5c3f4ec
Hendrik Schnepel authored
Showing with 12 additions and 15 deletions.
  1. +12 −15 lib/couchdb.js
View
27 lib/couchdb.js
@@ -150,12 +150,15 @@ exports.createClient = function(port, host, user, pass, maxListeners) {
options.headers
),
cbFired = false,
- onClose = function(hadError, reason) {
- if (hadError && !cbFired) cb && cb(new Error(reason));
- httpClient.removeListener('close', onClose);
+ onError = function(reason) {
+ if (!cbFired) cb && cb(new Error(reason));
+ },
+ onClose = function() {
+ if (!cbFired) cb && cb();
};
- httpClient.addListener('close', onClose);
+ request.addListener('error', onError);
+ request.addListener('close', onClose);
if (options.data && typeof options.data != 'string') {
options.data = exports.toJSON(options.data);
@@ -596,7 +599,7 @@ Db.prototype.changesStream = function(query, options) {
request = client.request('GET', path, headers),
buffer = '';
- client.setTimeout(options.timeout);
+ request.setTimeout(options.timeout);
request.addListener("response", function(res) {
res.addListener('data', function(chunk) {
buffer += (chunk || '');
@@ -620,20 +623,14 @@ Db.prototype.changesStream = function(query, options) {
stream.emit('data', change);
}
})
+ res.addListener('close', function(hadError) {
+ stream.emit('end', hadError);
+ });
});
request.end();
- client.addListener('close', function(hadError) {
- stream.emit('end', hadError);
- });
-
stream.close = function() {
- if (request.abort) {
- return request.abort();
- }
- else {
- return client.destroy();
- }
+ return request.abort();
};
return stream;
Please sign in to comment.
Something went wrong with that request. Please try again.