rx_rust/operators/utility/
do_after_subscription.rs1use crate::utils::types::NecessarySendSync;
2use crate::{
3 disposable::subscription::Subscription,
4 observable::{Observable, observable_ext::ObservableExt},
5 observer::Observer,
6};
7use educe::Educe;
8
9#[derive(Educe)]
34#[educe(Debug, Clone)]
35pub struct DoAfterSubscription<OE, F> {
36 source: OE,
37 callback: F,
38}
39
40impl<OE, F> DoAfterSubscription<OE, F> {
41 pub fn new<'or, 'sub, T, E>(source: OE, callback: F) -> Self
42 where
43 OE: Observable<'or, 'sub, T, E>,
44 F: FnOnce(),
45 {
46 Self { source, callback }
47 }
48}
49
50impl<'or, 'sub, T, E, OE, F> Observable<'or, 'sub, T, E> for DoAfterSubscription<OE, F>
51where
52 T: 'or,
53 E: 'or,
54 OE: Observable<'or, 'sub, T, E>,
55 F: FnOnce(),
56{
57 fn subscribe(
58 self,
59 observer: impl Observer<T, E> + NecessarySendSync + 'or,
60 ) -> Subscription<'sub> {
61 self.source
62 .hook_on_subscription(move |observable, observer| {
63 let sub = observable.subscribe(observer);
64 (self.callback)();
65 sub
66 })
67 .subscribe(observer)
68 }
69}