beanstalkd
Advanced tools
Comparing version 2.0.0 to 2.0.1
@@ -144,4 +144,3 @@ 'use strict'; | ||
let onConnectionEnded, | ||
connection = this.connection, | ||
let connection = this.connection, | ||
protocol = this.protocol, | ||
@@ -159,10 +158,9 @@ spec = protocol.commandMap[command], | ||
yield this.writeQueue; | ||
let defered = defer(); | ||
let onConnectionEnded = function onConnectionEnded(error) { | ||
defered.reject(error || new Error('CONNECTION_CLOSED')); | ||
}; | ||
try { | ||
result = new _bluebird2.default(function (resolve, reject) { | ||
onConnectionEnded = function onConnectionEnded(error) { | ||
reject(error || new Error('CONNECTION_CLOSED')); | ||
}; | ||
result = this.writeQueue.then(function () { | ||
connection.once('close', onConnectionEnded); | ||
@@ -176,3 +174,3 @@ connection.once('error', onConnectionEnded); | ||
resolve(result); | ||
defered.resolve(result); | ||
}, function (err) { | ||
@@ -182,9 +180,11 @@ connection.removeListener('close', onConnectionEnded); | ||
reject(err); | ||
defered.reject(err); | ||
}); | ||
}); | ||
writer.handle.apply(writer, [protocol, connection].concat(args)); | ||
writer.handle.apply(writer, [protocol, connection].concat(args)).catch(defered.reject); | ||
return defered.promise; | ||
}); | ||
this.writeQueue = result.reflect(); | ||
this.writeQueue = defered.promise.reflect(); | ||
@@ -210,8 +210,16 @@ yield result; | ||
/* | ||
handler.writer = writer; | ||
handler.reader = reader; | ||
*/ | ||
return handler; | ||
} | ||
return handler; | ||
function defer() { | ||
let resolve, reject; | ||
let promise = new _bluebird2.default(function () { | ||
resolve = arguments[0]; | ||
reject = arguments[1]; | ||
}); | ||
return { | ||
resolve: resolve, | ||
reject: reject, | ||
promise: promise | ||
}; | ||
} |
{ | ||
"name": "beanstalkd", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A beanstalkd client for Node.js with promises", | ||
@@ -8,3 +8,3 @@ "main": "lib/client.js", | ||
"babel-runtime": "^5.8.25", | ||
"beanstalkd-protocol": "^0.2.2", | ||
"beanstalkd-protocol": "^0.2.3", | ||
"bluebird": "^3.4.7", | ||
@@ -11,0 +11,0 @@ "debug": "^2.2.0", |
@@ -59,2 +59,8 @@ import Client from '../../src/client'; | ||
expect(stats.hostname).to.be.ok; | ||
return Promise.join( | ||
this.client.stats(), | ||
this.client.stats(), | ||
this.client.stats() | ||
); | ||
}); | ||
@@ -61,0 +67,0 @@ }); |
import BeanstalkdClient from 'client'; | ||
import {expect} from 'chai'; | ||
import Promise from 'bluebird'; | ||
import sinon from 'sinon'; | ||
@@ -91,2 +92,3 @@ import net from 'net'; | ||
await client.writeQueue; | ||
promise = client.watch(Math.random().toString()).then(function() { | ||
@@ -96,4 +98,3 @@ return client.reserve(); | ||
await client.writeQueue; | ||
await Promise.delay(1); | ||
this.connectionStub.emit('close'); | ||
@@ -116,2 +117,3 @@ | ||
await client.writeQueue; | ||
promise = client.watch(Math.random().toString()).then(function() { | ||
@@ -121,4 +123,3 @@ return client.reserve(); | ||
await client.writeQueue; | ||
await Promise.delay(1); | ||
expect(this.connectionStub.listenerCount('close')).to.equal(2); | ||
@@ -125,0 +126,0 @@ expect(this.connectionStub.listenerCount('error')).to.equal(2); |
41459
802
Updatedbeanstalkd-protocol@^0.2.3