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

Fetch files asynchronously #19

Merged
merged 1 commit into from Sep 2, 2023
Merged

Fetch files asynchronously #19

merged 1 commit into from Sep 2, 2023

Conversation

MatheusRich
Copy link
Owner

@MatheusRich MatheusRich commented Sep 2, 2023

Closes #16

This uses the async gem to parallelize fetching files from the GitHub API. The app is heavily IO-bound, so this is a good way to speed it up.

In my tests, this decreased the time to print results from 25s to around 2.5s.

@MatheusRich MatheusRich force-pushed the async-http-requests branch 3 times, most recently from 067298b to 961b2e1 Compare September 2, 2023 19:04
This uses the `async` gem to parallelize fetching files from the GitHub API.
The app is heavily IO-bound, so this is a good way to speed it up.

In my tests, this decreased the time to print results from 25s to around 2s.

Note: We're not taking advantage of the FiberScheduler here, because we would
need Ruby 3.1 to run async 2.x.
@MatheusRich MatheusRich marked this pull request as ready for review September 2, 2023 19:08
@MatheusRich MatheusRich merged commit aaeb5b0 into main Sep 2, 2023
5 checks passed
@MatheusRich MatheusRich deleted the async-http-requests branch September 2, 2023 19:13
repositories.filter { |repo| repo.eol_ruby?(at: max_eol_date) }
Sync do
repositories
.tap { |repos| repos.map { |repo| Async { repo.ruby_version } }.map(&:wait) }
Copy link

Choose a reason for hiding this comment

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

If you are doing this a lot, you might find https://github.com/socketry/async-await/blob/main/lib/async/await/enumerable.rb#L24-L30 convenient.

Copy link
Owner Author

Choose a reason for hiding this comment

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

That is pretty cool, @ioquatix. Could that be included in Async optionally? So one would include async/enumerable to get those methods?

Choose a reason for hiding this comment

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

I think it's better this is a separate gem, as it's a monkey patch.

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.

Make HTTP requests in parallel
2 participants