Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 55 lines (46 sloc) 1.03 kB
05d7412 @tadzik Initial commit
authored
1 use MuEvent;
2
3 MuEvent::timer(
4 after => 2,
5 cb => sub { say "2 seconds have passed" },
6 );
7
8 MuEvent::timer(
9 after => 0,
10 interval => 5,
11 cb => sub { say "I run every 5 seconds" },
12 );
13
14 MuEvent::idle(
15 cb => sub { say "Nothing better to do"; sleep 1 },
16 );
17
18 my $l = IO::Socket::INET.new(
19 :localhost('localhost'),
20 :localport(6666),
21 :listen
22 );
23
24 MuEvent::socket(
25 socket => $l,
26 poll => 'r',
27 cb => &socket-cb,
f4b61ff @tadzik Give events a params parameter, which is fed to callbacks
authored
28 params => { sock => $l },
05d7412 @tadzik Initial commit
authored
29 );
30
f4b61ff @tadzik Give events a params parameter, which is fed to callbacks
authored
31 sub socket-cb(:$sock) {
05d7412 @tadzik Initial commit
authored
32 say "Oh gosh a client!";
f4b61ff @tadzik Give events a params parameter, which is fed to callbacks
authored
33 my $s = $sock.accept;
34
05d7412 @tadzik Initial commit
authored
35 MuEvent::socket(
36 socket => $s,
37 poll => 'r',
f4b61ff @tadzik Give events a params parameter, which is fed to callbacks
authored
38 params => { sock => $s },
39 cb => sub (:$sock) {
40 my $a = $sock.recv;
05d7412 @tadzik Initial commit
authored
41 if $a {
42 print "Incoming transmission: $a";
43 return True;
44 } else {
45 say "Client disconnected";
f4b61ff @tadzik Give events a params parameter, which is fed to callbacks
authored
46 $sock.close;
05d7412 @tadzik Initial commit
authored
47 return False;
48 }
49 }
50 );
51 return True;
52 }
53
54 MuEvent::run;
Something went wrong with that request. Please try again.