From 117d59ea2f02e1538eedb1784bb783973ad4f84b Mon Sep 17 00:00:00 2001 From: Raycho Mukelov Date: Fri, 22 Sep 2023 04:34:44 +0300 Subject: [PATCH] Fix --- raft/consensus_module.nim | 4 ++-- raft/raft_api.nim | 2 +- tests/basic_timers.nim | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/raft/consensus_module.nim b/raft/consensus_module.nim index a4cdb5f..4c7efa9 100644 --- a/raft/consensus_module.nim +++ b/raft/consensus_module.nim @@ -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: diff --git a/raft/raft_api.nim b/raft/raft_api.nim index ecae4b0..cdf4c3f 100644 --- a/raft/raft_api.nim +++ b/raft/raft_api.nim @@ -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) diff --git a/tests/basic_timers.nim b/tests/basic_timers.nim index 5f29765..cf9e33c 100644 --- a/tests/basic_timers.nim +++ b/tests/basic_timers.nim @@ -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() \ No newline at end of file