Skip to content

A peristent logger where messages are not dropped until the configured quorum of readers have read a message

Notifications You must be signed in to change notification settings

obbap1/spmc-logger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A peristent logger where messages are not dropped until the configured quorum of readers have read a message

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages