From 5640d98f035a6babe1652087922e009909c286f7 Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 5 Sep 2023 09:49:32 +0200 Subject: [PATCH] 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 --- das.nim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/das.nim b/das.nim index 2084aae..74437e9 100644 --- a/das.nim +++ b/das.nim @@ -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)