1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use crate::prelude::*;

pub struct Using<'a> {
  subscription: Subscription<'a>,
}

impl<'a> Using<'a> {
  pub fn new(subscription: Subscription<'a>) -> Using<'a> {
    Using { subscription }
  }
}

impl<'a> Drop for Using<'a> {
  fn drop(&mut self) {
    self.subscription.unsubscribe();
  }
}

#[cfg(all(test, not(feature = "web")))]
mod test {
  use crate::prelude::*;
  use std::{thread, time};

  #[test]
  fn basic() {
    {
      let _using = utils::Using::new(
        observables::interval(
          time::Duration::from_millis(10),
          schedulers::new_thread_scheduler(),
        )
        .subscribe(
          print_next_fmt!("{}"),
          print_error!(),
          print_complete!(),
        ),
      );
      thread::sleep(time::Duration::from_millis(500));
    }
    println!("scope out");
    thread::sleep(time::Duration::from_millis(500));
  }
}