This commit is contained in:
Raycho Mukelov 2023-09-22 04:34:44 +03:00
parent b950cf289d
commit 117d59ea2f
3 changed files with 4 additions and 4 deletions

View File

@ -63,7 +63,7 @@ proc RaftNodeAbortElection*[SmCommandType, SmStateType](node: RaftNode[SmCommand
waitFor cancelAndWait(fut)
proc RaftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType]) {.async.} =
mixin RaftNodeScheduleElectionTimeout
mixin RaftNodeScheduleElectionTimeout, RaftTimerCreate
RaftNodeScheduleElectionTimeout(node)
withRLock(node.raftStateMutex):
@ -88,7 +88,7 @@ proc RaftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommand
# Process votes (if any)
for voteFut in node.votesFuts:
try:
await voteFut or sleepAsync(milliseconds(node.votingTimeout))
await voteFut or RaftTimerCreate(node.votingTimeout, proc()=discard)
if not voteFut.finished:
await cancelAndWait(voteFut)
else:

View File

@ -122,7 +122,7 @@ proc RaftNodeSmApply[SmCommandType, SmStateType](stateMachine: RaftNodeStateMach
RaftSmApply(stateMachine, command)
# Private Abstract Timer creation
template RaftTimerCreate(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] =
template RaftTimerCreate*(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] =
mixin RaftTimerCreateCustomImpl
RaftTimerCreateCustomImpl(timerInterval, timerCallback)

View File

@ -14,5 +14,5 @@ export raft_api
proc RaftTimerCreateCustomImpl*(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] {.async, nimcall, gcsafe.} =
var f = sleepAsync(milliseconds(timerInterval))
await f
if not f.cancelled:
if f.finished and not f.cancelled:
timerCallback()