rename states and callbacks to reflect current domain understanding

This commit is contained in:
gmega 2023-12-08 11:33:58 -03:00
parent 7474c5238d
commit c960f96be8
No known key found for this signature in database
GPG Key ID: FFD8DAF00660270F
4 changed files with 18 additions and 18 deletions

View File

@ -133,8 +133,8 @@ proc finish(fut: FutureBase, state: FutureState) =
# 2. `fut.state` is checked by `checkFinished()`.
fut.internalState = state
when chronosProfiling:
if not isNil(onFutureEvent):
onFutureEvent(fut, state)
if not isNil(onBaseFutureEvent):
onBaseFutureEvent(fut, state)
when chronosStrictFutureAccess:
doAssert fut.internalCancelcb == nil or state != FutureState.Cancelled
fut.internalCancelcb = nil # release cancellation callback memory
@ -316,8 +316,8 @@ proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.} =
var next: FutureBase
template iterate =
when chronosProfiling:
if not isNil(onFutureExecEvent):
onFutureExecEvent(fut, Running)
if not isNil(onAsyncFutureEvent):
onAsyncFutureEvent(fut, Running)
while true:
# Call closure to make progress on `fut` until it reaches `yield` (inside
@ -338,8 +338,8 @@ proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.} =
next.addCallback(CallbackFunc(internalContinue), cast[pointer](fut))
when chronosProfiling:
if not isNil(onFutureExecEvent):
onFutureExecEvent(fut, Paused)
if not isNil(onAsyncFutureEvent):
onAsyncFutureEvent(fut, Paused)
# return here so that we don't remove the closure below
return

View File

@ -94,11 +94,11 @@ when chronosFutureTracking:
var futureList* {.threadvar.}: FutureList
when chronosProfiling:
type FutureExecutionState* {.pure.} = enum
type AsyncFutureState* {.pure.} = enum
Running, Paused
var onFutureEvent* {.threadvar.}: proc (fut: FutureBase, state: FutureState): void {.nimcall, gcsafe, raises: [].}
var onFutureExecEvent* {.threadvar.}: proc(fut: FutureBase, state: FutureExecutionState): void {.nimcall, gcsafe, raises: [].}
var onBaseFutureEvent* {.threadvar.}: proc (fut: FutureBase, state: FutureState): void {.nimcall, gcsafe, raises: [].}
var onAsyncFutureEvent* {.threadvar.}: proc(fut: FutureBase, state: AsyncFutureState): void {.nimcall, gcsafe, raises: [].}
# Internal utilities - these are not part of the stable API
proc internalInitFutureBase*(
@ -129,8 +129,8 @@ proc internalInitFutureBase*(
futureList.count.inc()
when chronosProfiling:
if not isNil(onFutureEvent):
onFutureEvent(fut, state)
if not isNil(onBaseFutureEvent):
onBaseFutureEvent(fut, state)
# Public API
template init*[T](F: type Future[T], fromProc: static[string] = ""): Future[T] =

View File

@ -16,8 +16,8 @@ when chronosProfiling:
result = futureMetrics
proc enableEventCallbacks*(): void =
onFutureEvent = handleFutureEventCB
onFutureExecEvent = handleFutureExecEventCB
onBaseFutureEvent = handleBaseFutureEvent
onAsyncFutureEvent = handleAsyncFutureEvent
proc enableProfiling*() =
## Enables profiling on the current event loop.

View File

@ -36,7 +36,7 @@ proc mkEvent(future: FutureBase, state: ExtendedFutureState): Event =
timestamp: Moment.now(),
)
proc handleFutureEventCB*(future: FutureBase,
proc handleBaseFutureEvent*(future: FutureBase,
state: FutureState): void {.nimcall.} =
{.cast(gcsafe).}:
let extendedState = case state:
@ -48,12 +48,12 @@ proc handleFutureEventCB*(future: FutureBase,
if not isNil(handleFutureEvent):
handleFutureEvent(mkEvent(future, extendedState))
proc handleFutureExecEventCB*(future: FutureBase,
state: FutureExecutionState): void {.nimcall.} =
proc handleAsyncFutureEvent*(future: FutureBase,
state: AsyncFutureState): void {.nimcall.} =
{.cast(gcsafe).}:
let extendedState = case state:
of FutureExecutionState.Running: ExtendedFutureState.Running
of FutureExecutionState.Paused: ExtendedFutureState.Paused
of AsyncFutureState.Running: ExtendedFutureState.Running
of AsyncFutureState.Paused: ExtendedFutureState.Paused
if not isNil(handleFutureEvent):
handleFutureEvent(mkEvent(future, extendedState))