Add remote.disconnect callback

This commit is contained in:
wltsmrz
2013-12-05 17:10:04 -08:00
parent dbdfc262b6
commit 4a027bdcdf

View File

@@ -235,7 +235,7 @@ Remote.from_config = function(obj, trace) {
var remote = new Remote(serverConfig, trace);
function initializeAccount(account) {
var accountInfo = config.accounts[account];
var accountInfo = this.accounts[account];
if (typeof accountInfo === 'object') {
if (accountInfo.secret) {
// Index by nickname
@@ -246,11 +246,7 @@ Remote.from_config = function(obj, trace) {
}
};
if (typeof config.accounts === 'object') {
for (var account in config.accounts) {
initializeAccount(account);
}
}
Object.keys(config.accounts || {}).forEach(initializeAccount, config);
return remote;
};
@@ -387,11 +383,15 @@ Remote.prototype.connect = function(online) {
/**
* Disconnect from the Ripple network.
*/
Remote.prototype.disconnect = function(online) {
Remote.prototype.disconnect = function(callback) {
if (!this._servers.length) {
throw new Error('No servers available, not disconnecting');
}
if (typeof callback === 'function') {
this.once('disconnect', callback);
}
this._servers.forEach(function(server) {
server.disconnect();
});