Skip to content

Commit

Permalink
Merge pull request #52 from TrustyFund/feature/nodes-manager-ping-nod…
Browse files Browse the repository at this point in the history
…es-fix

fx nodes pinging
  • Loading branch information
youaresofunny authored Apr 2, 2018
2 parents 81465df + acbb8d0 commit 1d0f75a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/services/api/chain-listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ class ChainListener {
this._subscribers = [];
this._enabled = false;
}
enable() {
if (this._enabled) this.disable();
async enable() {
if (this._enabled) await this.disable();
Apis.instance().db_api().exec('set_subscribe_callback', [this._mainCallback.bind(this), true]);
this._enabled = true;
}
disable() {
Apis.instance().db_api().exec('cancel_all_subscriptions', []).then(() => {
return Apis.instance().db_api().exec('cancel_all_subscriptions', []).then(() => {
this._enabled = false;
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/services/api/nodes-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class NodesManager {
// gets nodes ping data from storage
_retrieveCachedNodesData() {
const cachedData = PersistentStorage.getSavedNodesData();
if (!cachedData) return;
Object.keys(this._nodes).forEach(url => {
const cachedNode = cachedData[url];
if (cachedNode && cachedNode.ping && typeof (cachedNode.ping) === 'number') {
Expand Down Expand Up @@ -54,16 +55,13 @@ class NodesManager {
testNodesPings() {
const cachedData = PersistentStorage.getSavedNodesData();
if (cachedData) return;
// return new Promise((resolve) => {
Promise.all(Object.keys(this._nodes).map(async (url) => {
if (url !== this._selectedNodeUrl) {
this._nodes[url].ping = await NodesManager._pingNode(url);
}
})).then(() => {
PersistentStorage.saveNodesData({ data: this._nodes }, { expires: 1 });
// resolve();
PersistentStorage.saveNodesData({ data: this._nodes });
});
// });
}

// retrieves nodes data from cache, selects fastest & returns it's url
Expand Down
4 changes: 2 additions & 2 deletions src/services/persistent-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ const PersistentStorage = {
Cookies.remove('BITSHARES_USER_BRAINKEY');
},
saveNodesData: ({ data }) => {
Cookies.set('BITSHARES_NODES', data);
Cookies.set('BITSHARES_NODES', data, { expires: 1 });
},
getSavedNodesData: () => {
const cachedData = Cookies.getJSON('BITSHARES_NODES');
if (typeof (cachedData) === 'object' && cachedData !== null) {
return cachedData;
}
return {};
return null;
},
getOpenledgerAddresses: () => {
const cachedData = Cookies.getJSON('BITSHARES_OPENLEDGER_ADDRESSES');
Expand Down

0 comments on commit 1d0f75a

Please sign in to comment.