kubo/thirdparty/datastore2/datastore_closer.go
Jeromy d7dab3afea Use gx vendored go-ipfs-utils where possible
For the rest of the packages in util, move them to thirdparty
and update the references. util is gone!

License: MIT
Signed-off-by: Jeromy <jeromyj@gmail.com>
2016-02-12 17:21:40 -08:00

36 lines
704 B
Go

package datastore2
import (
"io"
"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/ipfs/go-datastore"
)
type ThreadSafeDatastoreCloser interface {
datastore.ThreadSafeDatastore
io.Closer
Batch() (datastore.Batch, error)
}
func CloserWrap(ds datastore.ThreadSafeDatastore) ThreadSafeDatastoreCloser {
return &datastoreCloserWrapper{ds}
}
type datastoreCloserWrapper struct {
datastore.ThreadSafeDatastore
}
func (w *datastoreCloserWrapper) Close() error {
return nil // no-op
}
func (w *datastoreCloserWrapper) Batch() (datastore.Batch, error) {
bds, ok := w.ThreadSafeDatastore.(datastore.Batching)
if !ok {
return nil, datastore.ErrBatchUnsupported
}
return bds.Batch()
}