mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-28 10:28:09 -04:00
* Bunch of new warns due to a stronger clippy config * Moving old processing stuff to a new namespace Also fixing a bunch of typos through the entire codebase. * Rustfmt
35 lines
968 B
Rust
35 lines
968 B
Rust
use crate::api::notifications::Notification;
|
|
|
|
use std::sync::{atomic::AtomicU32, Arc};
|
|
|
|
use tokio::sync::broadcast;
|
|
|
|
#[derive(Clone)]
|
|
pub struct Notifications(
|
|
// Keep this private and use `Node::emit_notification` or `Library::emit_notification` instead.
|
|
broadcast::Sender<Notification>,
|
|
// Counter for `NotificationId::Node(_)`. NotificationId::Library(_, _)` is autogenerated by the DB.
|
|
Arc<AtomicU32>,
|
|
);
|
|
|
|
impl Notifications {
|
|
#[allow(clippy::new_without_default)]
|
|
pub fn new() -> Self {
|
|
let (tx, _) = broadcast::channel(30);
|
|
Self(tx, Arc::new(AtomicU32::new(0)))
|
|
}
|
|
|
|
pub fn subscribe(&self) -> broadcast::Receiver<Notification> {
|
|
self.0.subscribe()
|
|
}
|
|
|
|
/// DO NOT USE THIS. Use `Node::emit_notification` or `Library::emit_notification` instead.
|
|
pub fn _internal_send(&self, notification: Notification) {
|
|
self.0.send(notification).ok();
|
|
}
|
|
|
|
pub fn _internal_next_id(&self) -> u32 {
|
|
self.1.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
|
|
}
|
|
}
|