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 ../streams
|
||||
import ../loopmeasure
|
||||
import ../asyncyeah
|
||||
|
||||
import ./coders
|
||||
import ./json
|
||||
|
@ -339,9 +340,13 @@ proc initRestApi*(node: CodexNodeRef, conf: CodexConf, loopMeasure: LoopMeasure)
|
|||
|
||||
when defined(chronosDurationThreshold):
|
||||
var breaches = newSeq[string]()
|
||||
proc onBreach(stackTrace: string, durationUs: int64) =
|
||||
error "Duration threshold breached", durationUs, stackTrace
|
||||
breaches.add($durationUs & " usecs at " & stackTrace)
|
||||
proc onBreach(durationUs: int64) =
|
||||
var trace = ""
|
||||
for entry in globalYeahStack:
|
||||
trace = trace & " -> " & entry
|
||||
|
||||
error "Duration threshold breached", durationUs, trace
|
||||
breaches.add($durationUs & " usecs: " & trace)
|
||||
|
||||
setChronosDurationThresholdBreachedHandler(onBreach)
|
||||
|
||||
|
|
|
@ -19,9 +19,10 @@ import ./repostore
|
|||
import ../utils/timer
|
||||
import ../clock
|
||||
import ../systemclock
|
||||
import ../asyncyeah
|
||||
|
||||
const
|
||||
DefaultBlockMaintenanceInterval* = 10.minutes
|
||||
DefaultBlockMaintenanceInterval* = 10.seconds
|
||||
DefaultNumberOfBlocksToMaintainPerInterval* = 1000
|
||||
|
||||
type
|
||||
|
@ -42,9 +43,9 @@ proc new*(
|
|||
clock: Clock = SystemClock.new()
|
||||
): BlockMaintainer =
|
||||
## Create new BlockMaintainer instance
|
||||
##
|
||||
##
|
||||
## Call `start` to begin looking for for expired blocks
|
||||
##
|
||||
##
|
||||
BlockMaintainer(
|
||||
repoStore: repoStore,
|
||||
interval: interval,
|
||||
|
@ -63,7 +64,7 @@ proc processBlockExpiration(self: BlockMaintainer, be: BlockExpiration): Future[
|
|||
else:
|
||||
inc self.offset
|
||||
|
||||
proc runBlockCheck(self: BlockMaintainer): Future[void] {.async.} =
|
||||
proc runBlockCheck(self: BlockMaintainer): Future[void] {.asyncyeah.} =
|
||||
let expirations = await self.repoStore.getBlockExpirations(
|
||||
maxNumber = self.numberOfBlocksPerInterval,
|
||||
offset = self.offset
|
||||
|
|
Loading…
Reference in New Issue