feat: add BVK exchange library

This commit is contained in:
Георгий
2026-07-12 20:44:44 +03:00
parent 3a1c524eb2
commit 0ff0905a9c
15 changed files with 627 additions and 0 deletions

47
store_memory.go Normal file
View File

@@ -0,0 +1,47 @@
package mila
import (
"context"
"sync"
)
type MemoryStore struct {
mu sync.RWMutex
state ContentState
ready bool
}
func NewMemoryStore() *MemoryStore {
return &MemoryStore{}
}
func (s *MemoryStore) Get(ctx context.Context) (ContentState, error) {
select {
case <-ctx.Done():
return ContentState{}, ctx.Err()
default:
}
s.mu.RLock()
defer s.mu.RUnlock()
if !s.ready {
return ContentState{}, ErrNotReady
}
return s.state, nil
}
func (s *MemoryStore) Set(ctx context.Context, state ContentState) error {
select {
case <-ctx.Done():
return ctx.Err()
default:
}
s.mu.Lock()
defer s.mu.Unlock()
s.state = state
s.ready = true
return nil
}