@@ -115,14 +115,13 @@ class Raft[S, A <: Command](
115115 lastTerm <- logStore.lastTerm
116116 lastIndex <- logStore.lastIndex
117117 result <-
118- if (
118+ if
119119 currentTerm == m.term && (votedFor.contains(
120120 m.candidateId
121121 ) || votedFor.isEmpty) &&
122122 (m.lastLogTerm > lastTerm ||
123123 (m.lastLogTerm == lastTerm &&
124124 m.lastLogIndex >= lastIndex))
125- )
126125 then
127126 for
128127 _ <- stable.voteFor(m.candidateId)
@@ -241,7 +240,7 @@ class Raft[S, A <: Command](
241240 else if success then
242241 for
243242 _ <- ZIO .when(m.previousIndex < lastIndex)(
244- ZIO .foreachDiscard(m.entries)(entry => {
243+ ZIO .foreachDiscard(m.entries)(entry =>
245244 for
246245 logTerm <- logStore.logTerm(entry.index)
247246 _ <- ZIO .when(
@@ -250,7 +249,7 @@ class Raft[S, A <: Command](
250249 logStore.deleteFrom(entry.index)
251250 )
252251 yield ()
253- } )
252+ )
254253 )
255254 _ <- logStore.storeLogs(m.entries)
256255 messageLastIndex = m.entries.last.index
@@ -777,6 +776,8 @@ class Raft[S, A <: Command](
777776 )
778777 yield ()
779778 yield ()
779+ end for
780+ end sendAppendEntries
780781
781782 private def sendRequestVoteRule (peer : MemberId ) =
782783 for
@@ -929,10 +930,10 @@ class Raft[S, A <: Command](
929930 // todo: leader only
930931 for
931932 promiseArg <- Promise .make[NotALeaderError , commandArg.Response ]
932- _ <- commandsQueue.offer(new CommandMessage {
933+ _ <- commandsQueue.offer(new CommandMessage :
933934 val command = commandArg
934935 val promise = promiseArg.asInstanceOf
935- } )
936+ )
936937 res <- promiseArg.await
937938 yield (res)
938939
@@ -1081,3 +1082,4 @@ object Raft:
10811082 )
10821083 _ <- raft.run.forkScoped
10831084 yield raft
1085+ end Raft
0 commit comments