Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

dmihal
Copy link
Contributor

@dmihal dmihal commented Jan 27, 2018

Discussed in #252

@holgerd77
Copy link
Member

Whew. What a PR! 👍 🍰 😄

@holgerd77
Copy link
Member

@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.

@dmihal
Copy link
Contributor Author

dmihal commented Jan 27, 2018

@holgerd77 It looks bigger than it is, since it re-indents most of the public API functions.

Here's the diff with whitespace ignored

@holgerd77
Copy link
Member

@dmihal Ah, didn’t realize this on first look. 😄

@yann300 Does this PR create any potential problems for remix?

@holgerd77
Copy link
Member

@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) }
Copy link
Member

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.

Copy link
Member

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)
  }
}

@dmihal
Copy link
Contributor Author

dmihal commented Mar 6, 2018

Going to close this, #273 is a much cleaner change

@dmihal dmihal closed this Mar 6, 2018
holgerd77 added a commit that referenced this pull request Mar 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants