mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-06 15:33:08 +00:00
rename states and callbacks to reflect current domain understanding
This commit is contained in:
parent
7474c5238d
commit
c960f96be8
@ -133,8 +133,8 @@ proc finish(fut: FutureBase, state: FutureState) =
|
|||||||
# 2. `fut.state` is checked by `checkFinished()`.
|
# 2. `fut.state` is checked by `checkFinished()`.
|
||||||
fut.internalState = state
|
fut.internalState = state
|
||||||
when chronosProfiling:
|
when chronosProfiling:
|
||||||
if not isNil(onFutureEvent):
|
if not isNil(onBaseFutureEvent):
|
||||||
onFutureEvent(fut, state)
|
onBaseFutureEvent(fut, state)
|
||||||
when chronosStrictFutureAccess:
|
when chronosStrictFutureAccess:
|
||||||
doAssert fut.internalCancelcb == nil or state != FutureState.Cancelled
|
doAssert fut.internalCancelcb == nil or state != FutureState.Cancelled
|
||||||
fut.internalCancelcb = nil # release cancellation callback memory
|
fut.internalCancelcb = nil # release cancellation callback memory
|
||||||
@ -316,8 +316,8 @@ proc futureContinue*(fut: FutureBase) {.raises: [], gcsafe.} =
|
|||||||
var next: FutureBase
|
var next: FutureBase
|
||||||
template iterate =
|
template iterate =
|
||||||
when chronosProfiling:
|
when chronosProfiling:
|
||||||
if not isNil(onFutureExecEvent):
|
if not isNil(onAsyncFutureEvent):
|
||||||
onFutureExecEvent(fut, Running)
|
onAsyncFutureEvent(fut, Running)
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
# Call closure to make progress on `fut` until it reaches `yield` (inside
|
# 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))
|
next.addCallback(CallbackFunc(internalContinue), cast[pointer](fut))
|
||||||
|
|
||||||
when chronosProfiling:
|
when chronosProfiling:
|
||||||
if not isNil(onFutureExecEvent):
|
if not isNil(onAsyncFutureEvent):
|
||||||
onFutureExecEvent(fut, Paused)
|
onAsyncFutureEvent(fut, Paused)
|
||||||
|
|
||||||
# return here so that we don't remove the closure below
|
# return here so that we don't remove the closure below
|
||||||
return
|
return
|
||||||
|
|||||||
@ -94,11 +94,11 @@ when chronosFutureTracking:
|
|||||||
var futureList* {.threadvar.}: FutureList
|
var futureList* {.threadvar.}: FutureList
|
||||||
|
|
||||||
when chronosProfiling:
|
when chronosProfiling:
|
||||||
type FutureExecutionState* {.pure.} = enum
|
type AsyncFutureState* {.pure.} = enum
|
||||||
Running, Paused
|
Running, Paused
|
||||||
|
|
||||||
var onFutureEvent* {.threadvar.}: proc (fut: FutureBase, state: FutureState): void {.nimcall, gcsafe, raises: [].}
|
var onBaseFutureEvent* {.threadvar.}: proc (fut: FutureBase, state: FutureState): void {.nimcall, gcsafe, raises: [].}
|
||||||
var onFutureExecEvent* {.threadvar.}: proc(fut: FutureBase, state: FutureExecutionState): 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
|
# Internal utilities - these are not part of the stable API
|
||||||
proc internalInitFutureBase*(
|
proc internalInitFutureBase*(
|
||||||
@ -129,8 +129,8 @@ proc internalInitFutureBase*(
|
|||||||
futureList.count.inc()
|
futureList.count.inc()
|
||||||
|
|
||||||
when chronosProfiling:
|
when chronosProfiling:
|
||||||
if not isNil(onFutureEvent):
|
if not isNil(onBaseFutureEvent):
|
||||||
onFutureEvent(fut, state)
|
onBaseFutureEvent(fut, state)
|
||||||
|
|
||||||
# Public API
|
# Public API
|
||||||
template init*[T](F: type Future[T], fromProc: static[string] = ""): Future[T] =
|
template init*[T](F: type Future[T], fromProc: static[string] = ""): Future[T] =
|
||||||
|
|||||||
@ -16,8 +16,8 @@ when chronosProfiling:
|
|||||||
result = futureMetrics
|
result = futureMetrics
|
||||||
|
|
||||||
proc enableEventCallbacks*(): void =
|
proc enableEventCallbacks*(): void =
|
||||||
onFutureEvent = handleFutureEventCB
|
onBaseFutureEvent = handleBaseFutureEvent
|
||||||
onFutureExecEvent = handleFutureExecEventCB
|
onAsyncFutureEvent = handleAsyncFutureEvent
|
||||||
|
|
||||||
proc enableProfiling*() =
|
proc enableProfiling*() =
|
||||||
## Enables profiling on the current event loop.
|
## Enables profiling on the current event loop.
|
||||||
|
|||||||
@ -36,7 +36,7 @@ proc mkEvent(future: FutureBase, state: ExtendedFutureState): Event =
|
|||||||
timestamp: Moment.now(),
|
timestamp: Moment.now(),
|
||||||
)
|
)
|
||||||
|
|
||||||
proc handleFutureEventCB*(future: FutureBase,
|
proc handleBaseFutureEvent*(future: FutureBase,
|
||||||
state: FutureState): void {.nimcall.} =
|
state: FutureState): void {.nimcall.} =
|
||||||
{.cast(gcsafe).}:
|
{.cast(gcsafe).}:
|
||||||
let extendedState = case state:
|
let extendedState = case state:
|
||||||
@ -48,12 +48,12 @@ proc handleFutureEventCB*(future: FutureBase,
|
|||||||
if not isNil(handleFutureEvent):
|
if not isNil(handleFutureEvent):
|
||||||
handleFutureEvent(mkEvent(future, extendedState))
|
handleFutureEvent(mkEvent(future, extendedState))
|
||||||
|
|
||||||
proc handleFutureExecEventCB*(future: FutureBase,
|
proc handleAsyncFutureEvent*(future: FutureBase,
|
||||||
state: FutureExecutionState): void {.nimcall.} =
|
state: AsyncFutureState): void {.nimcall.} =
|
||||||
{.cast(gcsafe).}:
|
{.cast(gcsafe).}:
|
||||||
let extendedState = case state:
|
let extendedState = case state:
|
||||||
of FutureExecutionState.Running: ExtendedFutureState.Running
|
of AsyncFutureState.Running: ExtendedFutureState.Running
|
||||||
of FutureExecutionState.Paused: ExtendedFutureState.Paused
|
of AsyncFutureState.Paused: ExtendedFutureState.Paused
|
||||||
|
|
||||||
if not isNil(handleFutureEvent):
|
if not isNil(handleFutureEvent):
|
||||||
handleFutureEvent(mkEvent(future, extendedState))
|
handleFutureEvent(mkEvent(future, extendedState))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user