fix: use proper object reference in hashing (#85)

Uses `addr obj[]` instead of `addr obj`, fix tests.

Signed-off-by: Giuliano Mega <giuliano.mega@gmail.com>
This commit is contained in:
Giuliano Mega 2026-02-09 10:01:13 -03:00 committed by GitHub
parent c2c1f55a22
commit 1d22c62325
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View File

@ -1,7 +1,7 @@
mode = ScriptMode.Verbose
packageName = "datastore"
version = "0.2.2"
version = "0.2.3"
author = "Status Research & Development GmbH"
description = "Simple, unified API for multiple data stores"
license = "Apache License 2.0 or MIT"

View File

@ -6,6 +6,7 @@ import std/os
import std/strformat
import std/strutils
import std/sets
import std/sequtils
import pkg/leveldbstatic
import pkg/chronos
@ -23,7 +24,7 @@ type
openIterators: HashSet[QueryIter]
proc hash(iter: QueryIter): Hash =
hash(addr iter)
hash(addr iter[])
method has*(self: LevelDbDatastore, key: Key): Future[?!bool] {.async: (raises: [CancelledError]).} =
try:
@ -75,7 +76,7 @@ method put*(self: LevelDbDatastore, batch: seq[BatchEntry]): Future[?!void] {.as
method close*(self: LevelDbDatastore): Future[?!void] {.async: (raises: [CancelledError]).} =
try:
for iter in self.openIterators:
for iter in self.openIterators.toSeq:
if err =? (await iter.dispose()).errorOption:
return failure(err.msg)
self.openIterators.clear()
@ -163,6 +164,9 @@ method modify*(
if not lock.locked:
self.locks.del(key)
proc openIteratorCount*(self: LevelDbDatastore): int =
self.openIterators.len
proc new*(
T: type LevelDbDatastore, dbName: string): ?!T =
try:

View File

@ -195,3 +195,10 @@ suite "LevelDB Query":
let iter = (await ds.query(q)).tryGet
(await iter.dispose()).tryGet
(await iter.dispose()).tryGet
test "should stop tracking iterator objects once those are disposed":
let q = Query.init(Key.init("/a/b/c").tryGet)
let iter = (await ds.query(q)).tryGet
check ds.openIteratorCount == 1
(await iter.dispose()).tryGet
check ds.openIteratorCount == 0