diff --git a/util/datastore2/delayed.go b/util/datastore2/delayed.go new file mode 100644 index 0000000000000000000000000000000000000000..b8670b2523d1e729b56480e1ece103033740e2d8 --- /dev/null +++ b/util/datastore2/delayed.go @@ -0,0 +1,42 @@ +package datastore2 + +import ( + datastore "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" + delay "github.com/jbenet/go-ipfs/util/delay" +) + +func WithDelay(ds datastore.Datastore, delay delay.D) datastore.Datastore { + return &delayed{ds: ds, delay: delay} +} + +type delayed struct { + ds datastore.Datastore + delay delay.D +} + +func (dds *delayed) Put(key datastore.Key, value interface{}) (err error) { + dds.delay.Wait() + return dds.ds.Put(key, value) +} + +func (dds *delayed) Get(key datastore.Key) (value interface{}, err error) { + dds.delay.Wait() + return dds.ds.Get(key) +} + +func (dds *delayed) Has(key datastore.Key) (exists bool, err error) { + dds.delay.Wait() + return dds.ds.Has(key) +} + +func (dds *delayed) Delete(key datastore.Key) (err error) { + dds.delay.Wait() + return dds.ds.Delete(key) +} + +func (dds *delayed) KeyList() ([]datastore.Key, error) { + dds.delay.Wait() + return dds.ds.KeyList() +} + +var _ datastore.Datastore = &delayed{}