feat: storage sync/async funcs
This commit is contained in:
@@ -102,7 +102,7 @@ func NewFS(storageRoot string) (*fsStorage, error) {
|
||||
|
||||
func (s *fsStorage) StateExistsAsync(callback func(bool, error)) {
|
||||
go func() {
|
||||
exists, err := s.FileExists(stateFileName)
|
||||
exists, err := s.StateExists()
|
||||
if callback != nil {
|
||||
callback(exists, err)
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func (s *fsStorage) StateExistsAsync(callback func(bool, error)) {
|
||||
|
||||
func (s *fsStorage) LoadStateAsync(callback func(client.State, error)) {
|
||||
go func() {
|
||||
state, err := s.loadStateSync()
|
||||
state, err := s.LoadState()
|
||||
if callback != nil {
|
||||
callback(state, err)
|
||||
}
|
||||
@@ -120,7 +120,7 @@ func (s *fsStorage) LoadStateAsync(callback func(client.State, error)) {
|
||||
|
||||
func (s *fsStorage) SaveStateAsync(state client.State, callback func(error)) {
|
||||
go func() {
|
||||
err := s.saveStateSync(state)
|
||||
err := s.SaveState(state)
|
||||
if callback != nil {
|
||||
callback(err)
|
||||
}
|
||||
@@ -253,7 +253,11 @@ func (s *fsStorage) ListFiles() ([]string, error) {
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (s *fsStorage) loadStateSync() (client.State, error) {
|
||||
func (s *fsStorage) StateExists() (bool, error) {
|
||||
return s.FileExists(stateFileName)
|
||||
}
|
||||
|
||||
func (s *fsStorage) LoadState() (client.State, error) {
|
||||
data, err := s.ReadFile(stateFileName)
|
||||
if err != nil {
|
||||
return client.State{}, err
|
||||
@@ -261,7 +265,7 @@ func (s *fsStorage) loadStateSync() (client.State, error) {
|
||||
return unmarshalState(data)
|
||||
}
|
||||
|
||||
func (s *fsStorage) saveStateSync(state client.State) error {
|
||||
func (s *fsStorage) SaveState(state client.State) error {
|
||||
data, err := marshalState(state)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user