spmc-logger

Crates.iospmc-logger
lib.rsspmc-logger
version0.1.0
sourcesrc
created_at2023-11-25 12:05:48.190797
updated_at2023-11-25 12:05:48.190797
descriptionA single-producer multi-consumer persistent logger
homepage
repositoryhttps://github.com/obbap1/spmc-logger/tree/master
max_upload_size
id1048229
size8,461
Obba Paschal (obbap1)

documentation

README

spmc-logger

This is a single writer multi reader logger. If message x is written to the logger, x isn't dropped from the logger till y number of readers have read it.

usage

Logger::new(NUM_OF_READERS, LOGGER_BUFFER_SIZE)
// Eg. This means this logger will hold a maximum of 100 messages and will drop a single message when 
// 3 readers have read it.
let l = Logger::new(3, 100)
// writing and reading
// Thread A
l.write("hello world")
// Thread B
// message can be an error if more readers outside the quorum is trying to read a message.
// it can be none if we've read all the messages in the buffer and some if there is a message to be read.

// when the reader reads a message, it also has a `is_valid` key which tells us if the bytes have been
// malformed somewhere between the writing and reading. Think of it as an integrity hash.
match l.read() {
    Ok(Some(message)) => println!(message),
    Ok(None) => (),
    Err(e) => ()
}

Example

The it_works test in src/lib.rs is a good example.

Commit count: 0

cargo fmt