This repository was archived by the owner on Mar 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
asyncified filters fixes #220 #213 #159 #230
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ddafe00
asyncified filters
frozeman d9ce08e
improved filter interval
frozeman 1d3d727
improved comment
frozeman f242489
add optional default block parameter to contract call fixes #159
frozeman 16252f3
imporved async callback adding, without setinterval
frozeman b6c49d4
improved async polling
frozeman 1aefebd
merged develop
frozeman 1495a0c
add comlexity push for poll, does only show on travis
frozeman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,7 @@ var RequestManager = function (provider) { | |
arguments.callee._singletonInstance = this; | ||
|
||
this.provider = provider; | ||
this.polls = []; | ||
this.polls = {}; | ||
this.timeout = null; | ||
this.poll(); | ||
}; | ||
|
@@ -156,7 +156,7 @@ RequestManager.prototype.setProvider = function (p) { | |
* @todo cleanup number of params | ||
*/ | ||
RequestManager.prototype.startPolling = function (data, pollId, callback, uninstall) { | ||
this.polls.push({data: data, id: pollId, callback: callback, uninstall: uninstall}); | ||
this.polls['poll_'+ pollId] = {data: data, id: pollId, callback: callback, uninstall: uninstall}; | ||
}; | ||
/*jshint maxparams:3 */ | ||
|
||
|
@@ -167,24 +167,21 @@ RequestManager.prototype.startPolling = function (data, pollId, callback, uninst | |
* @param {Number} pollId | ||
*/ | ||
RequestManager.prototype.stopPolling = function (pollId) { | ||
for (var i = this.polls.length; i--;) { | ||
var poll = this.polls[i]; | ||
if (poll.id === pollId) { | ||
this.polls.splice(i, 1); | ||
} | ||
} | ||
delete this.polls['poll_'+ pollId]; | ||
}; | ||
|
||
/** | ||
* Should be called to reset polling mechanism of request manager | ||
* Should be called to reset the polling mechanism of the request manager | ||
* | ||
* @method reset | ||
*/ | ||
RequestManager.prototype.reset = function () { | ||
this.polls.forEach(function (poll) { | ||
poll.uninstall(poll.id); | ||
}); | ||
this.polls = []; | ||
for (var key in this.polls) { | ||
if (this.polls.hasOwnProperty(key)) { | ||
this.polls[key].uninstall(); | ||
} | ||
} | ||
this.polls = {}; | ||
|
||
if (this.timeout) { | ||
clearTimeout(this.timeout); | ||
|
@@ -199,9 +196,10 @@ RequestManager.prototype.reset = function () { | |
* @method poll | ||
*/ | ||
RequestManager.prototype.poll = function () { | ||
/*jshint maxcomplexity: 6 */ | ||
this.timeout = setTimeout(this.poll.bind(this), c.ETH_POLLING_TIMEOUT); | ||
|
||
if (!this.polls.length) { | ||
if (this.polls === {}) { | ||
return; | ||
} | ||
|
||
|
@@ -210,24 +208,42 @@ RequestManager.prototype.poll = function () { | |
return; | ||
} | ||
|
||
var payload = Jsonrpc.getInstance().toBatchPayload(this.polls.map(function (data) { | ||
return data.data; | ||
})); | ||
var pollsData = []; | ||
var pollsKeys = []; | ||
for (var key in this.polls) { | ||
if (this.polls.hasOwnProperty(key)) { | ||
pollsData.push(this.polls[key].data); | ||
pollsKeys.push(key); | ||
} | ||
} | ||
|
||
if (pollsData.length === 0) { | ||
return; | ||
} | ||
|
||
var payload = Jsonrpc.getInstance().toBatchPayload(pollsData); | ||
|
||
var self = this; | ||
this.provider.sendAsync(payload, function (error, results) { | ||
// TODO: console log? | ||
if (error) { | ||
return; | ||
} | ||
|
||
if (!utils.isArray(results)) { | ||
throw errors.InvalidResponse(results); | ||
} | ||
|
||
results.map(function (result, index) { | ||
result.callback = self.polls[index].callback; | ||
return result; | ||
var key = pollsKeys[index]; | ||
// make sure the filter is still installed after arrival of the request | ||
if(self.polls[key]) { | ||
result.callback = self.polls[key].callback; | ||
return result; | ||
} else | ||
return false; | ||
}).filter(function (result) { | ||
return (!result) ? false : true; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor, could be also: return !!result; |
||
}).filter(function (result) { | ||
var valid = Jsonrpc.getInstance().isValidResponse(result); | ||
if (!valid) { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is different functionality, please separate it to another pr