mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-20 12:15:51 +00:00
Merge pull request #584 from darkdarkdragon/develop-RLJS-521
Add Remote.closeCurrentPathFind function, so current pathfind can be …
This commit is contained in:
@@ -1813,6 +1813,19 @@ Remote.prototype.findAccount = function(accountID) {
|
||||
return account ? account : this.addAccount(accountID);
|
||||
};
|
||||
|
||||
/**
|
||||
* Closes current pathfind, if there is one.
|
||||
* After that new pathfind can be created, without adding to queue.
|
||||
*
|
||||
* @return {void} -
|
||||
*/
|
||||
Remote.prototype.closeCurrentPathFind = function() {
|
||||
if (this._cur_path_find !== null) {
|
||||
this._cur_path_find.close();
|
||||
this._cur_path_find = null;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a pathfind
|
||||
*
|
||||
@@ -1822,6 +1835,10 @@ Remote.prototype.findAccount = function(accountID) {
|
||||
*/
|
||||
Remote.prototype.createPathFind = function(options, callback) {
|
||||
if (this._cur_path_find !== null) {
|
||||
if (callback === undefined) {
|
||||
throw new Error('Only one streaming pathfind ' +
|
||||
'request at a time is supported');
|
||||
}
|
||||
this._queued_path_finds.push({options, callback});
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1927,6 +1927,30 @@ describe('Remote', function() {
|
||||
pathfind.on('update', message => console.log(message));
|
||||
});
|
||||
|
||||
it('createPathFind - throw error without callback if already running', function() {
|
||||
const servers = [
|
||||
makeServer('wss://localhost:5006'),
|
||||
makeServer('wss://localhost:5007')
|
||||
];
|
||||
|
||||
remote._servers = servers;
|
||||
|
||||
const pathfindParam = {
|
||||
src_account: 'rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||
dst_account: 'rwxBjBC9fPzyQ9GgPZw6YYLNeRTSx5c2W6',
|
||||
dst_amount: '1/USD/rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||
src_currencies: [{
|
||||
currency: 'BTC', issuer: 'rwxBjBC9fPzyQ9GgPZw6YYLNeRTSx5c2W6'
|
||||
}]
|
||||
};
|
||||
remote.createPathFind(pathfindParam);
|
||||
remote.createPathFind(pathfindParam, () => {});
|
||||
assert.throws(
|
||||
function() {
|
||||
remote.createPathFind(pathfindParam);
|
||||
}, Error);
|
||||
});
|
||||
|
||||
it('Construct path_find create request', function() {
|
||||
const request = remote.requestPathFindCreate({
|
||||
source_account: 'rGr9PjmVe7MqEXTSbd3njhgJc2s5vpHV54',
|
||||
|
||||
Reference in New Issue
Block a user