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

Loop? #4

Closed
janbaudisch opened this issue Oct 14, 2017 · 2 comments
Closed

Loop? #4

janbaudisch opened this issue Oct 14, 2017 · 2 comments

Comments

@janbaudisch
Copy link

Is there any way to build a loop with the client?

This does not work:

let f = client.goto("http://url.tld")
    .and_then(move |_| {
        loop {
            client.by_selector('element') // <- never gets executed
            ...
        }
    });

But I am pretty sure there is some way to use futures to create a loop, I just don't really know where to start...

@janbaudisch janbaudisch changed the title Loop Loop? Oct 14, 2017
@jonhoo
Copy link
Owner

jonhoo commented Oct 14, 2017

That example should work just fine. Are you sure that you are then running f?
If you look at the example over at https://docs.rs/fantoccini/0.7.2/fantoccini/, notice that you need to do

core.run(f).unwrap();

This is the way futures work -- you first sort of "set up" a computation, and then execute it.

That said, this is a somewhat weird way of doing things. Do you actually want an infinite loop in there? Why not something like:

core.run(client.goto("http://url.tld")).unwrap();
while let Ok(e) = core.run(client.by_selector("element")) {
  // ...
}

@janbaudisch
Copy link
Author

I got it working with your explanation.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants