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)
|
waitFor cancelAndWait(fut)
|
||||||
|
|
||||||
proc RaftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType]) {.async.} =
|
proc RaftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommandType, SmStateType]) {.async.} =
|
||||||
mixin RaftNodeScheduleElectionTimeout
|
mixin RaftNodeScheduleElectionTimeout, RaftTimerCreate
|
||||||
RaftNodeScheduleElectionTimeout(node)
|
RaftNodeScheduleElectionTimeout(node)
|
||||||
|
|
||||||
withRLock(node.raftStateMutex):
|
withRLock(node.raftStateMutex):
|
||||||
@ -88,7 +88,7 @@ proc RaftNodeStartElection*[SmCommandType, SmStateType](node: RaftNode[SmCommand
|
|||||||
# Process votes (if any)
|
# Process votes (if any)
|
||||||
for voteFut in node.votesFuts:
|
for voteFut in node.votesFuts:
|
||||||
try:
|
try:
|
||||||
await voteFut or sleepAsync(milliseconds(node.votingTimeout))
|
await voteFut or RaftTimerCreate(node.votingTimeout, proc()=discard)
|
||||||
if not voteFut.finished:
|
if not voteFut.finished:
|
||||||
await cancelAndWait(voteFut)
|
await cancelAndWait(voteFut)
|
||||||
else:
|
else:
|
||||||
|
@ -122,7 +122,7 @@ proc RaftNodeSmApply[SmCommandType, SmStateType](stateMachine: RaftNodeStateMach
|
|||||||
RaftSmApply(stateMachine, command)
|
RaftSmApply(stateMachine, command)
|
||||||
|
|
||||||
# Private Abstract Timer creation
|
# Private Abstract Timer creation
|
||||||
template RaftTimerCreate(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] =
|
template RaftTimerCreate*(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] =
|
||||||
mixin RaftTimerCreateCustomImpl
|
mixin RaftTimerCreateCustomImpl
|
||||||
RaftTimerCreateCustomImpl(timerInterval, timerCallback)
|
RaftTimerCreateCustomImpl(timerInterval, timerCallback)
|
||||||
|
|
||||||
|
@ -14,5 +14,5 @@ export raft_api
|
|||||||
proc RaftTimerCreateCustomImpl*(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] {.async, nimcall, gcsafe.} =
|
proc RaftTimerCreateCustomImpl*(timerInterval: int, timerCallback: RaftTimerCallback): Future[void] {.async, nimcall, gcsafe.} =
|
||||||
var f = sleepAsync(milliseconds(timerInterval))
|
var f = sleepAsync(milliseconds(timerInterval))
|
||||||
await f
|
await f
|
||||||
if not f.cancelled:
|
if f.finished and not f.cancelled:
|
||||||
timerCallback()
|
timerCallback()
|
Loading…
x
Reference in New Issue
Block a user