Skip to content

Use iterator in GetOrFetchBatch #42

@jo-me

Description

@jo-me

Is your feature request related to a problem? Please describe.

For GetOrFetchBatch, have you thought about switching to an iterator-based approach?

There are different "delivery times" for items from the in-memory cache, distributed cache and the fetch function.
Depending on the use case it could be beneficial to make partial results available to the caller so that they can already be processed while the other items are still getting fetched. This could reduce API latencies or throughput times.

Describe the solution you'd like
Use golang's iterators either directly in GetOrFetchBatch or offer an alternative function.

Seq2[K, V any] allows iterating over pairs of values which is what GetOrFetchBatch aggregates and merges anyway from the different configured sources.

maps.Collect(..) can create the current result type (map[string]V) directly from this Seq2 iterator. So both response styles could easily be offered.

Additional context
See
https://pkg.go.dev/iter#hdr-Iterators
https://pkg.go.dev/iter#Seq2

Jochen Mehlhorn jochen.mehlhorn@mercedes-benz.com, Mercedes-Benz Tech Innovation GmbH

Provider Information

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions