Em Seg, 2009-02-02 às 15:12 -0800, Larry Wall escreveu:
> Roles are good, but what is this Char thing of which you speak?  It
> seems good neither for Unicode characters nor for keystroke sequences.  :)

I meant exactly in the sense of providing one of those abstractions, let
me rephrase it:

role IO::Unicode {
   method getc {...}
   method readline {...}
}

role IO::Term {
   method get_keystroke {...}
}

> On this non-blocking keystroke thing, I see a P6ish solution more like:
>     get_keystrokes() ==>> my @available;
>     # time passes
>     if @available { ... }
> That is, use the async capabilities already built into the language.
> (That's assuming the boolean value of @available doesn't block on the
> state of the feed.  If it does, we need some other way of expressing
> that test.  @available.now or some such.)

while the syntax solution is cool, it doesn't actually solve anything,
because in the end it needs to be resolved to some method call in some
object. But I see what you mean...

The problem is that iterators are not about beign async or blocking,
they're just about measuring how much you consume of the stream, which
means that an Iterator still needs to be async for look-aheads and do
blocking IO if it fells short of data.

That actually remembers me of the idea of auto-threading IO and making
it async. Let me try to make some example code of a HTTP handler:

my $io = Net::TCP.listen(:host<localhost>, :port(1234));
$io does IO::Async[EV];
$io.accepts: -> $conn {
   my %headers;
   my $data;
   my $waiting_headers = 1;
   for =$conn -> $line {
      if ($line && $waiting_headers) {
         my ($name, $val) = split(/\s*:\s*/, $line);
         $headers{$name} = $val;
      } elsif ($line) {
         $data ~= $line;
      } else {
         $waiting_headers = 0;
      }
   }
   $conn.write("200 OK\n\nSucessfull request\n");
};
EV.loop;

This could autothread the code received by accepts, using async IO.
About one and a half years ago you sent me a paper about something like
that in haskell.

daniel

Reply via email to