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

Refactor dataloaders into a general-purpose batching struct #1511

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

radazen
Copy link
Contributor

@radazen radazen commented Apr 30, 2024

What's new?

I occasionally find myself wanting a reusable batcher that can do what dataloaders do: open a batch with a max size and timeout, wait for requests to come in, submit all the queued up requests when the batch closes, etc. I've reused this pattern in our push notifications handling, and wanted to use it again for Kafka event handling.

This PR refactors the Dataloader[TKey, TResult] type to be a thin wrapper around a reusable batch.Batcher[TParam, TResult] class that can be reused in any other context where we want batching.

The most notable change is that the Load functions have been renamed to Do, since we don't really know if a generic batch is "loading" things or just executing commands and receiving a result status. The Dataloader wrapper maintains the existing Load function names, since those feel appropriate and idiomatic for a dataloader.

@radazen radazen requested a review from jarrel-b as a code owner April 30, 2024 19:40
@radazen radazen merged commit 56f66aa into main Apr 30, 2024
5 checks passed
@radazen radazen deleted the ezra/generic-batcher branch April 30, 2024 19:41
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.

1 participant