The main loop should not be checking to see if the socket is ready to read because that's the job of the event system. In your hybrid design, the main loop should just ask the event system every 1ms or so whether it has anything to do.

But, what is your main loop doing that can't be done in IO::Async?

Since perl is single-threaded, if you want anything to be event-driven, it should all be event-driven. That means you really do want to use ->run, and find a way to take the "main loop" of your script and re-package it into event-style code.

Most event systems have an "idle" event that fires whenever the application lacks events to process, and you can use that to continue doing segments of a larger bulk task. But, you have to keep the segments of that large task brief, or it will block the events. For instance, if you want your application to respond to a network message within 1ms, then the 'idle' event should not run for more than 1ms at a time.


In reply to Re^3: Net::Async::WebSocket::Server in a separate main loop by NERDVANA
in thread Net::Async::WebSocket::Server in a separate main loop by Talkabout

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.