mirror of
https://github.com/status-im/nim-raft.git
synced 2025-02-26 11:55:27 +00:00
Fix
This commit is contained in:
parent
b950cf289d
commit
117d59ea2f
@ -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:
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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()
|
Loading…
x
Reference in New Issue
Block a user