another_rxrust/utils/
using.rs1use crate::prelude::*;
2
3pub struct Using<'a> {
4 subscription: Subscription<'a>,
5}
6
7impl<'a> Using<'a> {
8 pub fn new(subscription: Subscription<'a>) -> Using<'a> {
9 Using { subscription }
10 }
11}
12
13impl<'a> Drop for Using<'a> {
14 fn drop(&mut self) {
15 self.subscription.unsubscribe();
16 }
17}
18
19#[cfg(all(test, not(feature = "web")))]
20mod test {
21 use crate::prelude::*;
22 use std::{thread, time};
23
24 #[test]
25 fn basic() {
26 {
27 let _using = utils::Using::new(
28 observables::interval(
29 time::Duration::from_millis(10),
30 schedulers::new_thread_scheduler(),
31 )
32 .subscribe(
33 print_next_fmt!("{}"),
34 print_error!(),
35 print_complete!(),
36 ),
37 );
38 thread::sleep(time::Duration::from_millis(500));
39 }
40 println!("scope out");
41 thread::sleep(time::Duration::from_millis(500));
42 }
43}