-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
enhancementNew feature or requestNew feature or requesthardpriority 1Highest priorityHighest priority
Description
The current ID generation function is a mild atrocity:
pub fn gen_id() -> i64 {
static STATE: Mutex<Option<Snowflake>> = Mutex::new(None);
STATE
.lock()
.unwrap()
.get_or_insert_with(|| Snowflake::default())
.generate()
}Making this all gated behind a mutex effectively defeats the purpose of parallelism in other parts of the program, yet finding a better solution is challenging. poem doesn't let servers have mutable state, yet the Snowflake ID generator needs to be mutable in order to update itself.
You can do something very questionable with a mix of dependency injection via poem's Data, RefCells, and unstable rust, but it isn't a good solution either.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requesthardpriority 1Highest priorityHighest priority