Fix unhandled rejection issue with connectToPersistentSubscription #44
This commit is contained in:
parent
1d21facd2c
commit
6634dee5f3
|
@ -519,7 +519,7 @@ EventStoreNodeConnection.prototype.subscribeToAllFrom = function(
|
||||||
* @param {UserCredentials} [userCredentials]
|
* @param {UserCredentials} [userCredentials]
|
||||||
* @param {number} [bufferSize]
|
* @param {number} [bufferSize]
|
||||||
* @param {boolean} [autoAck]
|
* @param {boolean} [autoAck]
|
||||||
* @return {EventStorePersistentSubscription}
|
* @return {Promise<EventStorePersistentSubscription>}
|
||||||
*/
|
*/
|
||||||
EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
|
EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
|
||||||
stream, groupName, eventAppeared, subscriptionDropped, userCredentials, bufferSize, autoAck
|
stream, groupName, eventAppeared, subscriptionDropped, userCredentials, bufferSize, autoAck
|
||||||
|
@ -536,9 +536,7 @@ EventStoreNodeConnection.prototype.connectToPersistentSubscription = function(
|
||||||
var subscription = new EventStorePersistentSubscription(
|
var subscription = new EventStorePersistentSubscription(
|
||||||
groupName, stream, eventAppeared, subscriptionDropped, userCredentials, this._settings.log,
|
groupName, stream, eventAppeared, subscriptionDropped, userCredentials, this._settings.log,
|
||||||
this._settings.verboseLogging, this._settings, this._handler, bufferSize, autoAck);
|
this._settings.verboseLogging, this._settings, this._handler, bufferSize, autoAck);
|
||||||
subscription.start();
|
return subscription.start();
|
||||||
|
|
||||||
return subscription;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -571,7 +569,7 @@ EventStoreNodeConnection.prototype.createPersistentSubscription = function(strea
|
||||||
* @public
|
* @public
|
||||||
* @param {string} stream
|
* @param {string} stream
|
||||||
* @param {string} groupName
|
* @param {string} groupName
|
||||||
* @param {string} settings
|
* @param {PersistentSubscriptionSettings} settings
|
||||||
* @param {UserCredentials} [userCredentials]
|
* @param {UserCredentials} [userCredentials]
|
||||||
* @returns {Promise.<PersistentSubscriptionUpdateResult>}
|
* @returns {Promise.<PersistentSubscriptionUpdateResult>}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,11 +35,12 @@ EventStorePersistentSubscriptionBase.prototype.start = function() {
|
||||||
this._stopped = false;
|
this._stopped = false;
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
this._startSubscription(this._subscriptionId, this._streamId, this._bufferSize, this._userCredentials,
|
return this._startSubscription(this._subscriptionId, this._streamId, this._bufferSize, this._userCredentials,
|
||||||
this._onEventAppeared.bind(this), this._onSubscriptionDropped.bind(this), this._settings)
|
this._onEventAppeared.bind(this), this._onSubscriptionDropped.bind(this), this._settings)
|
||||||
.then(function(subscription) {
|
.then(function(subscription) {
|
||||||
console.log('Subscription started.');
|
console.log('Subscription started.');
|
||||||
self._subscription = subscription;
|
self._subscription = subscription;
|
||||||
|
return self;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -78,6 +79,7 @@ EventStorePersistentSubscriptionBase.prototype.fail = function(events, action, r
|
||||||
this._subscription.notifyEventsFailed(ids, action, reason);
|
this._subscription.notifyEventsFailed(ids, action, reason);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//TODO: this should return a promise
|
||||||
EventStorePersistentSubscriptionBase.prototype.stop = function() {
|
EventStorePersistentSubscriptionBase.prototype.stop = function() {
|
||||||
if (this._verbose) this._log.debug("Persistent Subscription to %s: requesting stop...", this._streamId);
|
if (this._verbose) this._log.debug("Persistent Subscription to %s: requesting stop...", this._streamId);
|
||||||
this._enqueueSubscriptionDropNotification(SubscriptionDropReason.UserInitiated, null);
|
this._enqueueSubscriptionDropNotification(SubscriptionDropReason.UserInitiated, null);
|
||||||
|
|
|
@ -22,7 +22,7 @@ module.exports = {
|
||||||
},
|
},
|
||||||
//TODO: Update Persistent Subscription
|
//TODO: Update Persistent Subscription
|
||||||
'Test ConnectTo Persistent Subscription': function(test) {
|
'Test ConnectTo Persistent Subscription': function(test) {
|
||||||
test.expect(2);
|
test.expect(3);
|
||||||
var _doneCount = 0;
|
var _doneCount = 0;
|
||||||
function done(err) {
|
function done(err) {
|
||||||
test.ok(!err, err ? err.stack : '');
|
test.ok(!err, err ? err.stack : '');
|
||||||
|
@ -36,8 +36,12 @@ module.exports = {
|
||||||
function subscriptionDropped(connection, reason, error) {
|
function subscriptionDropped(connection, reason, error) {
|
||||||
done(error);
|
done(error);
|
||||||
}
|
}
|
||||||
var subscription = this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped);
|
var self = this;
|
||||||
this.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()])
|
this.conn.connectToPersistentSubscription(testStreamName, 'consumer-1', eventAppeared, subscriptionDropped)
|
||||||
|
.then(function(subscription) {
|
||||||
|
test.ok(subscription, "Subscription is null.");
|
||||||
|
return self.conn.appendToStream(testStreamName, client.expectedVersion.any, [createRandomEvent()]);
|
||||||
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
done();
|
done();
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue
Block a user