Crates.io | spmc-logger |
lib.rs | spmc-logger |
version | 0.1.0 |
source | src |
created_at | 2023-11-25 12:05:48.190797 |
updated_at | 2023-11-25 12:05:48.190797 |
description | A single-producer multi-consumer persistent logger |
homepage | |
repository | https://github.com/obbap1/spmc-logger/tree/master |
max_upload_size | |
id | 1048229 |
size | 8,461 |
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.
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) => ()
}
The it_works
test in src/lib.rs
is a good example.