2. ABOUT ME
• I've misunderstood event loops for over a decade
• 2–3 years ago I set out on a quest to really
understand them
• I failed
• but learned a few things
3. WE ALL START SOMEWHERE
<?php
echo "im in ur pagez, writin php!!1!"
?>
alert("Hi mom!");
4. WHY ISTHIS SO SLOW?…
for my $host (@hosts) {
say $host . " is " . (ping($host) ? "up" : "down");
}
for host in hosts:
print host + " is " + ("up" if ping(host) else "down")
11. –Apple, "Threaded Programming Guide:Thread Management"
“Another cost to consider when writing threaded
code is the production costs. Designing a threaded
application can sometimes require fundamental
changes to the way you organize your application’s
data structures. Making those changes might be
necessary to avoid the use of synchronization, which
can itself impose a tremendous performance penalty
on poorly designed applications. Designing those data
structures, and debugging problems in threaded code,
can increase the time it takes to develop a threaded
application.Avoiding those costs can create bigger
problems at runtime, however, if your threads spend
too much time waiting on locks or doing nothing.”
16. for host in hosts:
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.setblocking(0)
clientsocket.connect((host, port))
while 1:
reads, writes, fails = select.select(in, out, [], wait)
# do something with these handles
...
22. UNITY 3D GAME LOOP
• physics loop: runs until caught up to current frame
• event updates once per loop iteration ("tick")
• network events
• rendering
23. $.get("some/page.html", function (data) {
$("#response").html(data);
});
var req = http.request({path: 'some/page.html'}, function(res) {
res.on('data', function(data) {
console.log(data);
});
});
$ua->get('some/page.html', sub {
say pop->res->body;
});
26. CAVEAT EMPTOR
• event loops can be hard to work with
• don't use callbacks except for simple things
• use Promises, Futures and other abstractions
27. IMAGE CREDITS
• stopwatch, cloud, database, info by Austin Condiff
from the Noun Project
• server by aLf from the Noun Project
• browser by Cindy Hu from the Noun Project
• code by useiconic.com from the Noun Project