aboutsummaryrefslogtreecommitdiffhomepage
path: root/internal/state/join.go
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2025-10-30 18:43:55 +0900
committerOphestra <cat@gensokyo.uk>2025-10-30 18:43:55 +0900
commitebdcff1049fb979405677a823a47410df7ee7c4f (patch)
treea5a14d409e4bc9f3b4b2e2c15f6c23de5ad0755f /internal/state/join.go
parent46c5ce493638ea2d034bbbdb9449e93b66d0330f (diff)
internal/store: rename from state
This reduces collision with local variable names, and generally makes sense for the new store package, since it no longer specifies the state struct. Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'internal/state/join.go')
-rw-r--r--internal/state/join.go64
1 files changed, 0 insertions, 64 deletions
diff --git a/internal/state/join.go b/internal/state/join.go
deleted file mode 100644
index 43a19b1d..00000000
--- a/internal/state/join.go
+++ /dev/null
@@ -1,64 +0,0 @@
-package state
-
-import (
- "errors"
- "maps"
-
- "hakurei.app/hst"
-)
-
-var (
- ErrDuplicate = errors.New("store contains duplicates")
-)
-
-/*
-Joiner is the interface that wraps the Join method.
-
-The Join function uses Joiner if available.
-*/
-type Joiner interface {
- Join() (map[hst.ID]*hst.State, error)
-}
-
-// Join returns joined state entries of all active identities.
-func Join(s Store) (map[hst.ID]*hst.State, error) {
- if j, ok := s.(Joiner); ok {
- return j.Join()
- }
-
- var (
- aids []int
- entries = make(map[hst.ID]*hst.State)
-
- el int
- res map[hst.ID]*hst.State
- loadErr error
- )
-
- if ln, err := s.List(); err != nil {
- return nil, err
- } else {
- aids = ln
- }
-
- for _, aid := range aids {
- if _, err := s.Do(aid, func(c Cursor) {
- res, loadErr = c.Load()
- }); err != nil {
- return nil, err
- }
-
- if loadErr != nil {
- return nil, loadErr
- }
-
- // save expected length
- el = len(entries) + len(res)
- maps.Copy(entries, res)
- if len(entries) != el {
- return nil, ErrDuplicate
- }
- }
-
- return entries, nil
-}