notifyClients :: (RaftLog l e v) => Raft l e v -> Clients -> l -> RaftState v -> IO ()
notifyClients vRaft clients newLog newState = do
    maybeReply <- atomically $ do
        modifyTVar (raftContext vRaft) $ \oldRaft ->
            setRaftLog newLog $ setRaftState newState oldRaft
        maybeClient <- tryPeekMailbox clients
        case maybeClient of
            Nothing -> return Nothing
            Just (index,reply) ->
                if index <= (lastCommitted newLog)
                    then do
                        updatedRaft <- readTVar (raftContext vRaft)
                        _ <- readMailbox clients
                        return $ Just $ reply $ mkResult True updatedRaft
                    else return Nothing
    case maybeReply of
        Nothing -> do
            return ()
        Just reply -> reply
notifyClients :: (RaftLog l e v) => Raft l e v -> Clients -> l -> RaftState v -> IO ()
notifyClients vRaft clients newLog newState = do
    maybeReply <- atomically $ do
        modifyTVar (raftContext vRaft) $ \oldRaft ->
            setRaftLog newLog $ setRaftState newState oldRaft
        maybeClient <- tryPeekMailbox clients
        case maybeClient of
            Nothing -> return Nothing
            Just (index,reply) ->
                if index <= (lastCommitted newLog)
                    then do
                        updatedRaft <- readTVar (raftContext vRaft)
                        _ <- readMailbox clients
                        return $ Just $ reply $ mkResult True updatedRaft
                    else return Nothing
    case maybeReply of
        Nothing -> do
            return ()
        Just reply -> reply
notifyClients vRaft clients newLog newState = do
    maybeReply <- atomically $ do
        modifyTVar (raftContext vRaft) $ \oldRaft ->
            setRaftLog newLog $ setRaftState newState oldRaft
        maybeClient <- tryPeekMailbox clients
        case maybeClient of
            Nothing -> return Nothing
            Just (index,reply) ->
                if index <= (lastCommitted newLog)
                    then do
                        updatedRaft <- readTVar (raftContext vRaft)
                        _ <- readMailbox clients
                        return $ Just $ reply $ mkResult True updatedRaft
                    else return Nothing
    case maybeReply of
        Nothing -> do
            return ()
        Just reply -> reply