Forum
Take Tuple
Consume one exact match locally, with explicit append-failure and concurrency limits.
take(&Pattern).await selects one matching map entry, removes it, appends a TupleEntry::Take tombstone and returns its bytes. Duplicate values remain distinct entries. Matching order follows HashMap iteration, so this is not FIFO. If tombstone append fails, the map removal is not rolled back. This is not an atomic transaction between memory and storage. Serialize mixed write/take operations because they acquire locks in opposite order. Constructors do not replay the log after restart.
This example is checked against source signatures; it was not compiled or run during this documentation pass.
use std::sync::Arc;
use tokio::sync::RwLock;
use strand::{Strand, StrandConfig};
use forum::{Forum, Pattern};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dir = tempfile::tempdir()?;
let cfg = StrandConfig::default().with_storage(dir.path());
let strand = Arc::new(RwLock::new(Strand::new(cfg).await?));
let forum = Forum::new(strand);
forum.write(b"job-1".to_vec()).await?;
forum.write(b"job-1".to_vec()).await?; // two entries with identical payload
// Take consumes exactly one.
let first = forum.take(&Pattern(b"job-1".to_vec())).await?;
assert_eq!(first.as_deref(), Some(b"job-1".as_slice()));
// The second take consumes the other entry.
let second = forum.take(&Pattern(b"job-1".to_vec())).await?;
assert_eq!(second.as_deref(), Some(b"job-1".as_slice()));
// No more matches.
let third = forum.take(&Pattern(b"job-1".to_vec())).await?;
assert!(third.is_none());
Ok(())
}