formatting

This commit is contained in:
Ben 2025-02-11 12:43:55 +01:00
parent 5fa90c5c2f
commit c1f25f10cc
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 27 additions and 50 deletions

View File

@ -12,8 +12,7 @@ import ../state
import ../utils/datastoreutils
import ../utils/asyncdataevent
const
nodestoreName = "nodestore"
const nodestoreName = "nodestore"
type
NodeEntry* = object
@ -66,10 +65,7 @@ proc storeNodeIsNew(s: NodeStore, nid: Nid): Future[?!bool] {.async.} =
return failure(err)
if not exists:
let entry = NodeEntry(
id: nid,
lastVisit: 0
)
let entry = NodeEntry(id: nid, lastVisit: 0)
?await s.store.put(key, entry)
return success(not exists)
@ -88,7 +84,7 @@ proc processFoundNodes(s: NodeStore, nids: seq[Nid]): Future[?!void] {.async.} =
newNodes.add(nid)
if newNodes.len > 0:
? await s.fireNewNodesDiscovered(newNodes)
?await s.fireNewNodesDiscovered(newNodes)
return success()
proc iterateAll*(s: NodeStore, onNode: OnNodeEntry): Future[?!void] {.async.} =
@ -119,15 +115,8 @@ method stop*(s: NodeStore): Future[?!void] {.async.} =
await s.state.events.nodesFound.unsubscribe(s.sub)
return success()
proc new*(
T: type NodeStore,
state: State,
store: TypedDatastore
): NodeStore =
NodeStore(
state: state,
store: store
)
proc new*(T: type NodeStore, state: State, store: TypedDatastore): NodeStore =
NodeStore(state: state, store: store)
proc createNodeStore*(state: State): ?!NodeStore =
without ds =? createTypedDatastore(state.config.dataDir / "nodestore"), err:

View File

@ -113,4 +113,3 @@ proc pop*(this: List): Future[?!Nid] {.async.} =
proc len*(this: List): int =
this.items.len

View File

@ -22,7 +22,9 @@ proc newAsyncDataEvent*[T](): AsyncDataEvent[T] =
queue: newAsyncEventQueue[?T](), subscriptions: newSeq[AsyncDataEventSubscription]()
)
proc performUnsubscribe[T](event: AsyncDataEvent[T], subscription: AsyncDataEventSubscription) {.async.} =
proc performUnsubscribe[T](
event: AsyncDataEvent[T], subscription: AsyncDataEventSubscription
) {.async.} =
if subscription in event.subscriptions:
await subscription.listenFuture.cancelAndWait()
event.subscriptions.delete(event.subscriptions.find(subscription))
@ -35,7 +37,7 @@ proc subscribe*[T](
listenFuture: newFuture[void](),
fireEvent: newAsyncEvent(),
inHandler: false,
delayedUnsubscribe: false
delayedUnsubscribe: false,
)
proc listener() {.async.} =

View File

@ -25,9 +25,7 @@ suite "Nodestore":
ds = createTypedDatastore(dsPath).tryGet()
state = createMockState()
store = NodeStore.new(
state, ds
)
store = NodeStore.new(state, ds)
(await store.start()).tryGet()
@ -38,10 +36,7 @@ suite "Nodestore":
removeDir(dsPath)
test "nodeEntry encoding":
let entry = NodeEntry(
id: genNid(),
lastVisit: 123.uint64
)
let entry = NodeEntry(id: genNid(), lastVisit: 123.uint64)
let
bytes = entry.encode()
@ -83,8 +78,7 @@ suite "Nodestore":
await state.events.newNodesDiscovered.unsubscribe(sub)
test "nodesFound event should not fire newNodesDiscovered for previously seen nodes":
let
nid = genNid()
let nid = genNid()
# Make nid known first. Then subscribe.
(await state.events.nodesFound.fire(@[nid])).tryGet()
@ -97,8 +91,7 @@ suite "Nodestore":
inc count
return success()
let
sub = state.events.newNodesDiscovered.subscribe(onNewNodes)
let sub = state.events.newNodesDiscovered.subscribe(onNewNodes)
# Firing the event again should not trigger newNodesDiscovered for nid
(await state.events.nodesFound.fire(@[nid])).tryGet()

View File

@ -4,11 +4,7 @@ import ../../codexcrawler/utils/asyncdataevent
import ../../codexcrawler/types
import ../../codexcrawler/config
type
MockState* = ref object of State
# config*: Config
# events*: Events
type MockState* = ref object of State
proc createMockState*(): MockState =
MockState(

View File

@ -21,5 +21,3 @@ suite "Types":
check:
nid == Nid.fromBytes(bytes).tryGet()