feat(kv): Asyncify key-value#59
Conversation
Signed-off-by: Adam Reese <adam@reese.io>
| @@ -78,12 +78,27 @@ func (s *Store) Exists(key string) (bool, error) { | |||
|
|
|||
| // GetKeys returns all the keys from the store. | |||
| func (s *Store) GetKeys() ([]string, error) { | |||
There was a problem hiding this comment.
This looks like it won't allow async traversal - it seems to collect the whole lot in memory rather than allowing processing one at a time?
Or am I misunderstanding Go slices?
There was a problem hiding this comment.
Taking a second look at this, I think this should return (chan string, error) instead.
There was a problem hiding this comment.
An iterator is likely the right API choice here for modern idiomatic go, rather than forcing consumers to manage pulling from a channel themselves.
The unfortunate part of moving KV to channels tho is that it's a... not great perf tradeoff as a default/only option for collections
There was a problem hiding this comment.
Yeah, an iterator makes sense. It worked out fine here.
There was a problem hiding this comment.
@endocrimes I haven't spent much time with iter. Would this be the way to approach it? adamreese@32a5d8e. I can apply the changes to this PR for easier review if you think its sane.
There was a problem hiding this comment.
I tried a new approach returning iter.Seq2[string, error]
Realized that GetKeys should have a different return type.
Signed-off-by: Adam Reese <adam@reese.io>
Refactor key-value to use new async wit bindings.
GetKeys()now returns an iterator to allow the user to process them concurrently.