Hoverbear / old-raft-rs

[Incomplete] A Raft implementation in Rust
https://hoverbear.github.io/raft-rs/raft/
MIT License
266 stars 41 forks source link

Code smell improvement #46

Closed Hoverbear closed 9 years ago

Hoverbear commented 9 years ago

@james-darkfox noted this could improve.

WildCryptoFox commented 9 years ago
self.listener
    .accept().map_err(From::from)
    .and_then(|stream_opt| stream_opt.ok_or(
         Error::Io(io::Error::new(io::ErrorKind::WouldBlock,
                                  "listener.accept() returned None"))))
    .and_then(|stream| Connection::unknown(stream))
    .and_then(|connection| {
        scoped_debug!("new connection received: {:?}", connection);
        self.connections
            .insert(connection)
            .map_err(|_| Error::Raft(ErrorKind::ConnectionLimitReached))
    }) 
    .and_then(|token| self.connections[token].register(event_loop, token))
    .unwrap_or_else(|error| scoped_warn!("unable to accept connection: {}", error));