Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

refactor(async): Query #120

Merged
merged 20 commits into from
May 23, 2019
Merged

refactor(async): Query #120

merged 20 commits into from
May 23, 2019

Conversation

kumavis
Copy link
Contributor

@kumavis kumavis commented May 18, 2019

non-breaking async refactor for

  • Query
  • Run
  • Path
  • PeerQueue

this is intended to not introduce any changes in behavior

related #82

@kumavis
Copy link
Contributor Author

kumavis commented May 18, 2019

not included in this PR, I started on WorkerQueue but found that wrapping async implementation triggered some test failures. Looked like some deterministic race conditions in
this.run.continueQuerying vs run._continueQueryingAsync

edit: moving the discussion of this issue to this draft PR #121

@jacobheun
Copy link
Contributor

Since Query and the other internal classes aren't exported, wouldn't it be better to just make all of that async directly? It looks like a lot of the methods have been promisified and/or have async counterparts. Ideally we'd only promisify other libs that have not been migrated, and callbackify the dht public api. Since this is only for the Query migration I understand that it's internally used methods would need to be callbackified, but the other classes should be able to be fully async.

@kumavis
Copy link
Contributor Author

kumavis commented May 21, 2019

I wasn't sure if the other classes were considered public APIs or not, with respect to breaking changes. Thanks for the clarification.

I'll take a look at how much of the existing callback APIs are still in use in other parts of the package.

@kumavis
Copy link
Contributor Author

kumavis commented May 23, 2019

This PR takes us across the bundlesize, but note that I did not introduce any additional deps here

@kumavis
Copy link
Contributor Author

kumavis commented May 23, 2019

@jacobheun ready to go

  • remove callback based methods in private classes
    • peer-queue
      • cb methods not used elsewhere
      • cb methods not used by tests
      • cb methods removed
    • query/index - cb methods still used
      • cb methods not used elsewhere
      • cb methods not used by tests
      • cb methods removed
    • query/path
      • cb methods not used elsewhere
      • cb methods not used by tests
      • cb methods removed
    • query/run
      • cb methods not used elsewhere
      • cb methods not used by tests
      • cb methods removed
    • query/workerQueue
      • cb methods not used elsewhere
      • cb methods not used by tests
      • cb methods removed

@kumavis
Copy link
Contributor Author

kumavis commented May 23, 2019

ok, fixed a commit failing commitlint that was several commits back using interactive rebase. bleh

Copy link
Contributor

@jacobheun jacobheun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 minor comment in regards to documenting throws in the jsdocs.

Keeping in mind that this is designed to be a phased approach to async, I think this looks good. There are definitely things that can be cleaned up in the code, especially with the switch to async, but that should be done as a separate effort to avoid blocking these iterative changes.

callback(null, new PeerQueue(key))
})
static async fromPeerId (id) {
const key = await promisify(cb => utils.convertPeerId(id, cb))()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should throw now right? Should we add @throws to the jsdocs? It will make it easier for anyone consuming to know that they should ensure they're handling it. If so, we should add this to the other methods that also throw.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jacobheun Thats correct. What is the correct way to document throws for async functions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking more through the jsdocs repo there's not really a correct way, unfortunately. Ideally we'd be able to do something like this, jsdoc/jsdoc#1467, to be explicit.

For now, either way we have to do some level of assumption looking at the docs. Since the function is async, a throw is just a promise rejection. So we either need to catch it, or .catch the promise.

I suppose it makes sense to leave it out for now until the docs can be explicit.

Copy link
Member

@vasco-santos vasco-santos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Thanks for another iteration @kumavis

@vasco-santos vasco-santos merged commit ce15ec3 into master May 23, 2019
@vasco-santos vasco-santos deleted the feat/async-query branch May 23, 2019 09:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants