Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send events through channel #360

Closed
derolf opened this issue Feb 17, 2022 · 1 comment
Closed

Send events through channel #360

derolf opened this issue Feb 17, 2022 · 1 comment
Labels
documentation Issues about improvements or bugs in documentation help wanted question

Comments

@derolf
Copy link

derolf commented Feb 17, 2022

Look at this broken piece of code:

  let mut xml = Reader::from_reader(...);
  let (tx, rx) = mpsc::channel::<Event>();
  let mut buf = Vec::new();
  
  loop {
      let ev = xml.read_event(&mut buf);
      tx.send(ev.unwrap());
  }
}

I'd like to decode the XML in one thread and send the events via a channel. Do you have a minimum example on how to do this?

@Mingun
Copy link
Collaborator

Mingun commented Dec 7, 2022

This code is worked for me:

/// Regression test for https://github.com/tafia/quick-xml/issues/360
#[test]
fn issue360() {
    let mut r = Reader::from_str("<tag1 attr1='line 1\nline 2'></tag1>");
    let (tx, rx) = std::sync::mpsc::channel::<Event>();

    loop {
        match r.read_event() {
            Ok(Event::Eof) => break,
            ev => tx.send(ev.unwrap()).unwrap(),
        }
    }
    std::thread::spawn(move || {
        // Ok(Start(BytesStart { buf: Borrowed("tag1 attr1='line 10xAline 2'"), name_len: 4 }))
        println!("{:?}", rx.recv());
    }).join().unwrap();
}

@derolf, It that is not what you want, please add a comment

@Mingun Mingun closed this as completed Dec 7, 2022
Mingun added a commit to Mingun/quick-xml that referenced this issue Jan 8, 2023
dralley pushed a commit that referenced this issue Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Issues about improvements or bugs in documentation help wanted question
Projects
None yet
Development

No branches or pull requests

2 participants