-
Notifications
You must be signed in to change notification settings - Fork 779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add promise support to all public functions #253
Conversation
Whew. What a PR! 👍 🍰 😄 |
@dmihal The Circle tests can be ignored for now, they are not working atm (at least they have to be re-triggered to run through), passing travis is essential. |
@holgerd77 It looks bigger than it is, since it re-indents most of the public API functions. |
@dmihal Ah, tests passing, cool! |
this.trie.db.put(address, src, cb) | ||
var self = this | ||
return new Promise(function (resolve, reject) { | ||
cb = cb || function (err, result) { err ? reject(err) : resolve(result) } |
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.
I don't think it is a good idea to return a promise which will never resolve - that is the case when a callback is passed (e.g. the old-world compatibility mode).
Wouldn't it make sense keeping the old interface unchanged and adding a promise API in front (or the other way around).
Also I'd be supportive internally moving to promises, which is a lot of work, and that would mean that the call back interface would need become the wrapper API.
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.
Can't we just put the switch in an if statement to have a more clean implementation with not returning an unresolved promise and at the same time keep the original idea and not have an additional/second API?
VM.prototype._populateCache = function (addresses, cb) {
self.stateManager.warmCache(addresses, cb)
}
VM.prototype.populateCache = function (addresses, cb) {
if (!cb) {
var self = this
return new Promise(function (resolve, reject) {
cb = function (err, result) { err ? reject(err) : resolve(result) }
self._populateCache(addresses, cb)
})
} else {
self._populateCache(addresses, cb)
}
}
Going to close this, #273 is a much cleaner change |
Discussed in #252