Skip to content

Commit

Permalink
Implements proper iter dispose
Browse files Browse the repository at this point in the history
  • Loading branch information
benbierens committed May 20, 2024
1 parent dfe142f commit ec4754b
Show file tree
Hide file tree
Showing 2 changed files with 393 additions and 34 deletions.
7 changes: 7 additions & 0 deletions leveldbstatic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,11 @@ type
LevelDbException* = object of CatchableError

IterNext* = proc(): (string, string) {.gcsafe, closure.}
IterDispose* = proc() {.gcsafe, closure.}
LevelDbQueryIter* = ref object
finished*: bool
next*: IterNext
dispose*: IterDispose

const
version* = block:
Expand Down Expand Up @@ -477,8 +479,13 @@ proc queryIter*(self: LevelDb, prefix: string = "", keysOnly: bool = false, skip
else:
return (keyStr, valueStr)

proc dispose() {.gcsafe, closure.} =
if not iter.finished:
iter.closeIter(iterPtr)

iter.finished = false
iter.next = getNext
iter.dispose = dispose
return iter

proc removeDb*(name: string) =
Expand Down
Loading

0 comments on commit ec4754b

Please sign in to comment.