Remove methods taking non-async functions
This commit is contained in:
parent
3d38850afc
commit
f41bd9528e
|
@ -14,39 +14,18 @@ push: {.upraises: [].}
|
|||
|
||||
type
|
||||
Function*[T, U] = proc(value: T): U {.upraises: [CatchableError], gcsafe, closure.}
|
||||
Modify* = Function[?seq[byte], ?seq[byte]]
|
||||
ModifyGet* = Function[?seq[byte], (?seq[byte], seq[byte])]
|
||||
ModifyAsync* = Function[?seq[byte], Future[?seq[byte]]]
|
||||
ModifyGetAsync* = Function[?seq[byte], Future[(?seq[byte], seq[byte])]]
|
||||
Modify* = Function[?seq[byte], Future[?seq[byte]]]
|
||||
ModifyGet* = Function[?seq[byte], Future[(?seq[byte], seq[byte])]]
|
||||
|
||||
method modify*(self: ConcurrentDatastore, key: Key, fn: Modify): Future[?!void] {.base, locks: "unknown".} =
|
||||
## Concurrently safe way of modifying the value associated with the `key`.
|
||||
##
|
||||
## Same as `modifyGet` with `fn: ModifyGetAsync` argument, but this takes non-async `fn` that doesn't
|
||||
## produce any auxillary value.
|
||||
##
|
||||
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method modify*(self: ConcurrentDatastore, key: Key, fn: ModifyAsync): Future[?!void] {.base, locks: "unknown".} =
|
||||
## Concurrently safe way of modifying the value associated with the `key`.
|
||||
##
|
||||
## Same as `modifyGet` with `fn: ModifyGetAsync` argument, but this takes `fn` that doesn't produce
|
||||
## any auxillary value.
|
||||
## Same as `modifyGet`, but this takes `fn` that doesn't produce any auxillary value.
|
||||
##
|
||||
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method modifyGet*(self: ConcurrentDatastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] {.base, locks: "unknown".} =
|
||||
## Concurrently safe way of updating value associated with the `key`. Returns auxillary value on
|
||||
## successful update.
|
||||
##
|
||||
## Same as `modifyGet` with `fn: ModifyGetAsync` argument, but this takes non-async `fn`.
|
||||
##
|
||||
|
||||
raiseAssert("Not implemented!")
|
||||
|
||||
method modifyGet*(self: ConcurrentDatastore, key: Key, fn: ModifyGetAsync): Future[?!seq[byte]] {.base, locks: "unknown".} =
|
||||
## Concurrently safe way of updating value associated with the `key`. Returns auxillary value on
|
||||
## successful update.
|
||||
##
|
||||
|
|
|
@ -31,7 +31,7 @@ proc timestamp*(t = epochTime()): int64 =
|
|||
|
||||
const initVersion* = 0.int64
|
||||
|
||||
method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGetAsync): Future[?!seq[byte]] {.async.} =
|
||||
method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] {.async.} =
|
||||
var
|
||||
retriesLeft = 100 # allows reasonable concurrency, avoids infinite loop
|
||||
aux: seq[byte]
|
||||
|
@ -117,13 +117,8 @@ method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGetAsync): Future[?
|
|||
|
||||
return success(aux)
|
||||
|
||||
method modifyGet*(self: SQLiteDatastore, key: Key, fn: ModifyGet): Future[?!seq[byte]] {.async.} =
|
||||
proc wrappedFn(maybeValue: ?seq[byte]): Future[(?seq[byte], seq[byte])] {.async.} =
|
||||
return fn(maybeValue)
|
||||
|
||||
return await self.modifyGet(key, wrappedFn)
|
||||
|
||||
method modify*(self: SQLiteDatastore, key: Key, fn: ModifyAsync): Future[?!void] {.async.} =
|
||||
method modify*(self: SQLiteDatastore, key: Key, fn: Modify): Future[?!void] {.async.} =
|
||||
proc wrappedFn(maybeValue: ?seq[byte]): Future[(?seq[byte], seq[byte])] {.async.} =
|
||||
let res = await fn(maybeValue)
|
||||
let ignoredAux = newSeq[byte]()
|
||||
|
@ -134,17 +129,6 @@ method modify*(self: SQLiteDatastore, key: Key, fn: ModifyAsync): Future[?!void]
|
|||
else:
|
||||
return success()
|
||||
|
||||
method modify*(self: SQLiteDatastore, key: Key, fn: Modify): Future[?!void] {.async.} =
|
||||
proc wrappedFn(maybeValue: ?seq[byte]): Future[(?seq[byte], seq[byte])] {.async.} =
|
||||
let maybeNewValue = fn(maybeValue)
|
||||
let ignoredAux = newSeq[byte]()
|
||||
return (maybeNewValue, ignoredAux)
|
||||
|
||||
if err =? (await self.modifyGet(key, wrappedFn)).errorOption:
|
||||
return failure(err)
|
||||
else:
|
||||
return success()
|
||||
|
||||
method has*(self: SQLiteDatastore, key: Key): Future[?!bool] {.async.} =
|
||||
var
|
||||
exists = false
|
||||
|
|
|
@ -80,7 +80,7 @@ proc concurrentStoreTests*(
|
|||
test "should put value":
|
||||
(await ds.delete(key)).tryGet()
|
||||
|
||||
proc returningSomeValue(_: ?seq[byte]): ?seq[byte] =
|
||||
proc returningSomeValue(_: ?seq[byte]): Future[?seq[byte]] {.async.} =
|
||||
return @(123.uint64.toBytes).some
|
||||
|
||||
(await ds.modify(key, returningSomeValue)).tryGet
|
||||
|
@ -92,7 +92,7 @@ proc concurrentStoreTests*(
|
|||
test "should delete value":
|
||||
(await ds.put(key, @(0.uint64.toBytes))).tryGet
|
||||
|
||||
proc returningNone(_: ?seq[byte]): ?seq[byte] =
|
||||
proc returningNone(_: ?seq[byte]): Future[?seq[byte]] {.async.} =
|
||||
return seq[byte].none
|
||||
|
||||
(await ds.modify(key, returningNone)).tryGet
|
||||
|
@ -102,7 +102,7 @@ proc concurrentStoreTests*(
|
|||
check not hasKey
|
||||
|
||||
test "should return correct auxillary value":
|
||||
proc returningAux(_: ?seq[byte]): (?seq[byte], seq[byte]) =
|
||||
proc returningAux(_: ?seq[byte]): Future[(?seq[byte], seq[byte])] {.async.} =
|
||||
return (seq[byte].none, @[byte 123])
|
||||
|
||||
let result = await ds.modifyGet(key, returningAux)
|
||||
|
@ -111,7 +111,7 @@ proc concurrentStoreTests*(
|
|||
result == success(@[byte 123])
|
||||
|
||||
test "should propagate exception as failure":
|
||||
proc throwing(a: ?seq[byte]): ?seq[byte] =
|
||||
proc throwing(a: ?seq[byte]): Future[?seq[byte]] {.async.} =
|
||||
raise newException(CatchableError, "some error msg")
|
||||
|
||||
let result = await ds.modify(key, throwing)
|
||||
|
|
Loading…
Reference in New Issue