use findValue instead of the naive getValue

findValue combines lookup with value retrieval,
as it should be done for better performance.

Signed-off-by: Csaba Kiraly <csaba.kiraly@gmail.com>
This commit is contained in:
Csaba Kiraly 2023-09-05 09:49:32 +02:00
parent 9f7376ebef
commit 5640d98f03
No known key found for this signature in database
GPG Key ID: 0FE274EE8C95166E
1 changed files with 5 additions and 1 deletions

View File

@ -149,6 +149,10 @@ when isMainModule:
await sleepAsync(sampling_delay)
# sample
proc sampleOne(sampler: discv5_protocol.Protocol, cid: NodeId, startdelay: Duration = 0.milliseconds) : Future[DiscResult[seq[byte]]] {.async.} =
await sleepAsync(startdelay)
return await sampler.findValue(cid)
proc startSamplingDA(n: discv5_protocol.Protocol): (seq[int], seq[Future[DiscResult[seq[byte]]]]) =
## Generate random sample and start the sampling process
var futs = newSeq[Future[DiscResult[seq[byte]]]]()
@ -156,7 +160,7 @@ when isMainModule:
let sample = sample(0 ..< blocksize, samplesize)
debug "starting sampling", by = n, sample
for s in sample:
let fut = n.getValue(segmentIDs[s])
let fut = n.sampleOne(segmentIDs[s])
futs.add(fut)
return (sample, futs)