lazy

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("Datastore is closed")

Functions

This section is empty.

Types

type DataStoreOp

type DataStoreOp func() error

DataStoreOp is a Datastore operation

type LazyDatastore

type LazyDatastore struct {
	// contains filtered or unexported fields
}

LazyDatastore wraps a datastore with three states: active, inactive and closed. State can be changed by three StateChangeFuncs: activateFn, deactivateFn and closeFn. The relationship between states and StateChangeFuncs is as follows:

----------(deactivateFn)----------
|                                |  -(ensureActive)-
V                                | |               |

inactive -----(activateFn)------> active <------------

|                                |
--(closeFn)-> closed <-(closeFn)--

Every datastore operation will check that the datastore is in the `active` state or try to activate it with the `activateFn` StateChangeFunc, an error will occur if it fails.

func NewLazyDataStore

func NewLazyDataStore(wrapped datastore.Datastore, activateFn, deactivateFn, closeFn StateChangeFunc,
) (*LazyDatastore, error)

NewLazyDataStore creates a LazyStore.

func (*LazyDatastore) Activate

func (d *LazyDatastore) Activate() error

Activate the LazyDatastore. It doesn't ensure that LazyDatastore will be kept in `active` state, use EnsureActive for that.

func (*LazyDatastore) Close

func (d *LazyDatastore) Close() error

Close the LazyDatastore. Return `ErrClosed` if already closed. Close will NOT call `wrapped`'s closer, `closeFn` should do it.

func (*LazyDatastore) Deactivate

func (d *LazyDatastore) Deactivate() error

Deactivate the LazyDatastore.

func (*LazyDatastore) Delete

func (d *LazyDatastore) Delete(ctx context.Context, key key.Key) (err error)

Delete implements Datastore.Delete

func (*LazyDatastore) EnsureActive

func (d *LazyDatastore) EnsureActive(op DataStoreOp) error

EnsureActive makes sure that LazyDatastore is in active state and runs a DataStoreOp. It returns an error if it fails to activate the wrapped Datastore or `op` returns an error.

func (*LazyDatastore) Get

func (d *LazyDatastore) Get(ctx context.Context, key key.Key) (value []byte, err error)

Get implements Datastore.Get

func (*LazyDatastore) GetSize

func (d *LazyDatastore) GetSize(ctx context.Context, key key.Key) (size int, err error)

GetSize implements Datastore.GetSize

func (*LazyDatastore) Has

func (d *LazyDatastore) Has(ctx context.Context, key key.Key) (exists bool, err error)

Has implements Datastore.Has

func (*LazyDatastore) Put

func (d *LazyDatastore) Put(ctx context.Context, key key.Key, value []byte) (err error)

Put implements Datastore.Put

func (*LazyDatastore) Query

func (d *LazyDatastore) Query(ctx context.Context, q query.Query) (rs query.Results, err error)

Query implements Datastore.Query

func (*LazyDatastore) Sync

func (d *LazyDatastore) Sync(ctx context.Context, prefix key.Key) error

Sync implements Datastore.Sync

type StateChangeFunc

type StateChangeFunc func(ds datastore.Datastore) error

StateChangeFunc is a function that change a LazyStore's state

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL