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

Using generators internally + refactoring flow #23

Merged
merged 4 commits into from
Jul 10, 2015
Merged

Conversation

dominicbarnes
Copy link
Contributor

In preparation to add more async logic here (such as working with the cache) I've decided to change how this module is structured internally. Primarilly, it now uses generators instead of normal callbacks.

I'm using unyield so the API technically hasn't changed, although it does now require the --harmony-generators flag since it is using generators under the hood. I've also removed options.retries, as that is an internal detail that doesn't really need to be configurable at this time.

The main changes here:

  • moved main logic from index.js to lib/resolve.js
  • using generators internally + unyield to retain same high-level API
  • making debug output more consistent and easy to follow even in parallel
  • cleaning up flow through the program (delegating more to a cleaner lib/github.js)

I'm going to start working on a branch right away that leverages the new cache to store the results of Github API calls. (which should cut down on the number of API calls counting towards the limit)

In preparation to add more async logic here (such as working with the cache)
I've decided to change how this module is structured internally. Primarilly,
it now uses generators instead of normal callbacks.

I'm using `unyield` so the API _technically_ hasn't changed, although it does
now require the `--harmony-generators` flag since it is using generators under
the hood. I've also removed `options.retries`, as that is an internal detail
that doesn't really need to be configurable at this time.
*/

function* get(token, parts, attempts) {
var url = 'https://api.github.com/' + path.join.apply(path, parts);
Copy link
Contributor

Choose a reason for hiding this comment

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

will path.join() do weird stuff on windows (e.g. "https://api.github.com/foo\\bar\\")?

Copy link
Contributor

Choose a reason for hiding this comment

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

haha possibly related? duojs/duo#481

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh snap... you're probably right. We should use url.resolve instead anyways. Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this is directly related to that issue. That's probably somewhere in duo-pack, if I were to guess.

But it's still a good idea here to use url.resolve() w/o path.join() at all.

@stephenmathieson
Copy link
Contributor

lgtm :)

@matthewmueller
Copy link
Contributor

works for me!

dominicbarnes added a commit that referenced this pull request Jul 10, 2015
Using generators internally + refactoring flow
@dominicbarnes dominicbarnes merged commit 8927dd5 into master Jul 10, 2015
@dominicbarnes dominicbarnes deleted the generators branch July 10, 2015 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants