Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-datastore
Commits
eec3759d
Unverified
Commit
eec3759d
authored
Dec 26, 2018
by
Steven Allen
Committed by
GitHub
Dec 26, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #108 from ipfs/cleanup/export-delaystore
delayed: implement io.Closer and export datastore type.
parents
27c83074
21c2c0e8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
11 deletions
+33
-11
delayed/delayed.go
delayed/delayed.go
+33
-11
No files found.
delayed/delayed.go
View file @
eec3759d
...
...
@@ -3,56 +3,78 @@
package
delayed
import
(
"io"
ds
"github.com/ipfs/go-datastore"
dsq
"github.com/ipfs/go-datastore/query"
delay
"github.com/ipfs/go-ipfs-delay"
)
// New returns a new delayed datastore.
func
New
(
ds
ds
.
Datastore
,
delay
delay
.
D
)
ds
.
Datastore
{
return
&
d
elayed
{
ds
:
ds
,
delay
:
delay
}
func
New
(
ds
ds
.
Datastore
,
delay
delay
.
D
)
*
Delayed
{
return
&
D
elayed
{
ds
:
ds
,
delay
:
delay
}
}
type
delayed
struct
{
// Delayed is an adapter that delays operations on the inner datastore.
type
Delayed
struct
{
ds
ds
.
Datastore
delay
delay
.
D
}
func
(
dds
*
delayed
)
Put
(
key
ds
.
Key
,
value
[]
byte
)
(
err
error
)
{
var
_
ds
.
Batching
=
(
*
Delayed
)(
nil
)
var
_
io
.
Closer
=
(
*
Delayed
)(
nil
)
// Put implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
Put
(
key
ds
.
Key
,
value
[]
byte
)
(
err
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
Put
(
key
,
value
)
}
func
(
dds
*
delayed
)
Get
(
key
ds
.
Key
)
(
value
[]
byte
,
err
error
)
{
// Get implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
Get
(
key
ds
.
Key
)
(
value
[]
byte
,
err
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
Get
(
key
)
}
func
(
dds
*
delayed
)
Has
(
key
ds
.
Key
)
(
exists
bool
,
err
error
)
{
// Has implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
Has
(
key
ds
.
Key
)
(
exists
bool
,
err
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
Has
(
key
)
}
func
(
dds
*
delayed
)
GetSize
(
key
ds
.
Key
)
(
size
int
,
err
error
)
{
// GetSize implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
GetSize
(
key
ds
.
Key
)
(
size
int
,
err
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
GetSize
(
key
)
}
func
(
dds
*
delayed
)
Delete
(
key
ds
.
Key
)
(
err
error
)
{
// Delete implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
Delete
(
key
ds
.
Key
)
(
err
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
Delete
(
key
)
}
func
(
dds
*
delayed
)
Query
(
q
dsq
.
Query
)
(
dsq
.
Results
,
error
)
{
// Query implements the ds.Datastore interface.
func
(
dds
*
Delayed
)
Query
(
q
dsq
.
Query
)
(
dsq
.
Results
,
error
)
{
dds
.
delay
.
Wait
()
return
dds
.
ds
.
Query
(
q
)
}
func
(
dds
*
delayed
)
Batch
()
(
ds
.
Batch
,
error
)
{
// Batch implements the ds.Batching interface.
func
(
dds
*
Delayed
)
Batch
()
(
ds
.
Batch
,
error
)
{
return
ds
.
NewBasicBatch
(
dds
),
nil
}
func
(
dds
*
delayed
)
DiskUsage
()
(
uint64
,
error
)
{
// DiskUsage implements the ds.PersistentDatastore interface.
func
(
dds
*
Delayed
)
DiskUsage
()
(
uint64
,
error
)
{
dds
.
delay
.
Wait
()
return
ds
.
DiskUsage
(
dds
.
ds
)
}
// Close closes the inner datastore (if it implements the io.Closer interface).
func
(
dds
*
Delayed
)
Close
()
error
{
if
closer
,
ok
:=
dds
.
ds
.
(
io
.
Closer
);
ok
{
return
closer
.
Close
()
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment