diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2026-02-27 16:41:37 -0500 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2026-02-27 18:15:33 -0500 |
| commit | b32c7682f0a84619a6d1845516a6a1829fa0c59b (patch) | |
| tree | fad8bf5bd8eb628253611f0b3d1a91febe3b9266 /src/test/webpush.rs | |
| parent | 6ab0f42250294e38e8da6a48260ff83544a6be9a (diff) | |
I want push publication to be "fire and forget," and ultimately also for it to be asynchronous and retriable. To facilitate that, the caller needs to be insulated from the final outcome of publishing a push message. I've opted to preserve the `Failure` possibility, but any delivery issues are now handled inside the publisher.
Diffstat (limited to 'src/test/webpush.rs')
| -rw-r--r-- | src/test/webpush.rs | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/src/test/webpush.rs b/src/test/webpush.rs index 55caf19..656f66a 100644 --- a/src/test/webpush.rs +++ b/src/test/webpush.rs @@ -1,11 +1,11 @@ use std::{ any::Any, - collections::{HashMap, HashSet}, + collections::HashSet, mem, sync::{Arc, Mutex, MutexGuard}, }; -use web_push::{PartialVapidSignatureBuilder, SubscriptionInfo, WebPushError}; +use web_push::{PartialVapidSignatureBuilder, SubscriptionInfo}; use crate::{error::failed::Failed, push::Publish}; @@ -15,7 +15,6 @@ pub struct Client(Arc<Mutex<ClientInner>>); #[derive(Default)] struct ClientInner { sent: Vec<Publication>, - planned_failures: HashMap<SubscriptionInfo, WebPushError>, } impl Client { @@ -33,35 +32,23 @@ impl Client { let sent = &mut self.inner().sent; mem::take(sent) } - - pub fn fail_next(&self, subscription_info: &SubscriptionInfo, err: WebPushError) { - let planned_failures = &mut self.inner().planned_failures; - planned_failures.insert(subscription_info.clone(), err); - } } #[async_trait::async_trait] impl Publish for Client { - async fn publish<'s, M>( + async fn publish<M>( &self, message: M, _: &PartialVapidSignatureBuilder, - subscriptions: impl IntoIterator<Item = &'s SubscriptionInfo> + Send, - ) -> Result<Vec<(&'s SubscriptionInfo, WebPushError)>, Failed> + subscriptions: impl IntoIterator<Item = &'_ SubscriptionInfo> + Send, + ) -> Result<(), Failed> where M: Send + 'static, { let mut inner = self.inner(); - let message: Box<dyn Any + Send> = Box::new(message); - let mut recipients = HashSet::new(); - let mut failures = Vec::new(); - for subscription in subscriptions { - recipients.insert(subscription.clone()); - if let Some(err) = inner.planned_failures.remove(subscription) { - failures.push((subscription, err)); - } - } + let message: Box<dyn Any + Send> = Box::new(message); + let recipients = subscriptions.into_iter().cloned().collect(); let publication = Publication { message, @@ -69,7 +56,7 @@ impl Publish for Client { }; inner.sent.push(publication); - Ok(failures) + Ok(()) } } |
