in reply to LWP::UserAgent non-blocking calls

You could use threads.

But there are ways of making LWP::UserAgent do parallel calls. I'd recommend LWP::Protocol::AnyEvent::http for that.

But LWP is quite slow. Using libcurl is much faster, and it supports parallel requests. For a serious application, I'd use this.

Replies are listed 'Best First'.
Re^2: LWP::UserAgent non-blocking calls
by cavac (Prior) on Oct 23, 2024 at 14:46 UTC

    Speed and parallel requests are not a requirement in my case. Basically, i need to start a transaction on a credit/debit card payment terminal. Most have a sane API where you just start a transactions, then poll every few seconds to see if there is a result for that transaction (accepted/rejected). This one company made the idiotic decision to go for long polls (with a 60 second transaction timeout), like it's 1995.

    With a non-blocking HTTP client library, i can still simulate the standard behaviour. Marshall suggested HTTP::Async which, at first glance, seems to fit the bill (but i haven't tested it yet).

    PerlMonks XP is useless? Not anymore: XPD - Do more with your PerlMonks XP
    Also check out my sisters artwork and my weekly webcomics

      Speed and parallel requests are not a requirement in my case

      But you want parallelism, and the three options I mentioned provide that. And there are again, plus a fourth:

      You didn't say what you are doing in parallel. You didn't say what event loop you are using. So it's hard to evaluate which option will work and which is best. Provide more information, and we can provide a more detailed answer.