sets up asyncyeah
This commit is contained in:
parent
7401d4af64
commit
ed4fd8104b
|
@ -0,0 +1,33 @@
|
||||||
|
import std/[macros]
|
||||||
|
|
||||||
|
var globalYeahStack* {.global, threadvar.}: seq[string]
|
||||||
|
var globalYeahInt {.global, threadvar.}: int
|
||||||
|
|
||||||
|
macro asyncyeah*(functionlike: untyped{nkProcDef | nkMethodDef | nkFuncDef}): untyped =
|
||||||
|
let fl = functionlike.copyNimTree
|
||||||
|
let closureName = newStrLitNode($fl[0])
|
||||||
|
var body = fl[6].copyNimTree
|
||||||
|
|
||||||
|
var newBody = newStmtList()
|
||||||
|
newBody.add(quote do:
|
||||||
|
inc globalYeahInt
|
||||||
|
let callName = `closureName` & $globalYeahInt
|
||||||
|
# echo "push " & callName
|
||||||
|
globalYeahStack.add(callName)
|
||||||
|
defer:
|
||||||
|
let rmIndex = globalYeahStack.find(callName)
|
||||||
|
globalYeahStack.del(rmIndex)
|
||||||
|
# echo "pop " & callName
|
||||||
|
)
|
||||||
|
body.copyChildrenTo(newBody)
|
||||||
|
|
||||||
|
fl.body = newBody
|
||||||
|
|
||||||
|
let pragmas = fl[4]
|
||||||
|
var newPragmas = newNimNode(nnkPragma)
|
||||||
|
for pragma in pragmas:
|
||||||
|
if not pragma.eqIdent("asyncyeah"):
|
||||||
|
newPragmas.add(pragma)
|
||||||
|
newPragmas.add(ident("async"))
|
||||||
|
fl[4] = newPragmas
|
||||||
|
return fl
|
|
@ -36,6 +36,7 @@ import ../conf
|
||||||
import ../contracts
|
import ../contracts
|
||||||
import ../streams
|
import ../streams
|
||||||
import ../loopmeasure
|
import ../loopmeasure
|
||||||
|
import ../asyncyeah
|
||||||
|
|
||||||
import ./coders
|
import ./coders
|
||||||
import ./json
|
import ./json
|
||||||
|
@ -339,9 +340,13 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf, loopMeasure: LoopMeasure)
|
||||||
|
|
||||||
when defined(chronosDurationThreshold):
|
when defined(chronosDurationThreshold):
|
||||||
var breaches = newSeq[string]()
|
var breaches = newSeq[string]()
|
||||||
proc onBreach(stackTrace: string, durationUs: int64) =
|
proc onBreach(durationUs: int64) =
|
||||||
error "Duration threshold breached", durationUs, stackTrace
|
var trace = ""
|
||||||
breaches.add($durationUs & " usecs at " & stackTrace)
|
for entry in globalYeahStack:
|
||||||
|
trace = trace & " -> " & entry
|
||||||
|
|
||||||
|
error "Duration threshold breached", durationUs, trace
|
||||||
|
breaches.add($durationUs & " usecs: " & trace)
|
||||||
|
|
||||||
setChronosDurationThresholdBreachedHandler(onBreach)
|
setChronosDurationThresholdBreachedHandler(onBreach)
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,10 @@ import ./repostore
|
||||||
import ../utils/timer
|
import ../utils/timer
|
||||||
import ../clock
|
import ../clock
|
||||||
import ../systemclock
|
import ../systemclock
|
||||||
|
import ../asyncyeah
|
||||||
|
|
||||||
const
|
const
|
||||||
DefaultBlockMaintenanceInterval* = 10.minutes
|
DefaultBlockMaintenanceInterval* = 10.seconds
|
||||||
DefaultNumberOfBlocksToMaintainPerInterval* = 1000
|
DefaultNumberOfBlocksToMaintainPerInterval* = 1000
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -63,7 +64,7 @@ proc processBlockExpiration(self: BlockMaintainer, be: BlockExpiration): Future[
|
||||||
else:
|
else:
|
||||||
inc self.offset
|
inc self.offset
|
||||||
|
|
||||||
proc runBlockCheck(self: BlockMaintainer): Future[void] {.async.} =
|
proc runBlockCheck(self: BlockMaintainer): Future[void] {.asyncyeah.} =
|
||||||
let expirations = await self.repoStore.getBlockExpirations(
|
let expirations = await self.repoStore.getBlockExpirations(
|
||||||
maxNumber = self.numberOfBlocksPerInterval,
|
maxNumber = self.numberOfBlocksPerInterval,
|
||||||
offset = self.offset
|
offset = self.offset
|
||||||
|
|
Loading…
Reference in New Issue