Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6 0.96 KB | None | 0 0
  1. #!/usr/bin/env perl6
  2.  
  3. use v6.c;
  4.  
  5. class MockServer {
  6.  
  7.     has @.events is rw;
  8.  
  9.     method start-up() {
  10.         say 'server starting';
  11.         react {
  12.             whenever IO::Socket::Async.listen('127.0.0.1', 3005) -> $conn {
  13.                 say 'all up in my server';
  14.                 whenever $conn.Supply.lines -> $line {
  15.                     # send Initial message
  16.                     $conn.print("Hey there my dude.\r\n\r\n");
  17.                 }
  18.             }
  19.         }
  20.         say 'fuck it im done';
  21.     }
  22. }
  23.  
  24.  
  25.  
  26. my MockServer $mock-server = MockServer.new();
  27. Promise.in(1).then({
  28.    $mock-server.start-up();
  29. });
  30.  
  31. await IO::Socket::Async.connect('127.0.0.1', 3005).then( -> $promise {
  32.     given $promise.result {
  33.         .print("Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n");
  34.         react {
  35.             whenever .Supply() -> $v {
  36.                 $v.print;
  37.                 done;
  38.             }
  39.         }
  40.         .close;
  41.     }
  42. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement