From: Charles McGarvey Date: Sun, 17 Jun 2018 21:39:38 +0000 (-0600) Subject: add slides on exception handling X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=fa698f7b8f498a04b0394f5cadc2cadf0a6fb21a;p=chaz%2Ftalk-event-driven-programming-in-perl add slides on exception handling --- diff --git a/css/slides.css b/css/slides.css index 93fa174..abeeb12 100644 --- a/css/slides.css +++ b/css/slides.css @@ -10,7 +10,6 @@ width: 100%; } - .pizza img { width: 70%; } @@ -53,3 +52,11 @@ font-size: 32px; } +#slide-not-all-roses img { + width: 70%; +} + +.ex-exceptions .perl { + font-size: 38px; +} + diff --git a/img/thorn.jpg b/img/thorn.jpg new file mode 100644 index 0000000..4c7be52 Binary files /dev/null and b/img/thorn.jpg differ diff --git a/notes.txt b/notes.txt index 16f2f5c..0d32c72 100644 --- a/notes.txt +++ b/notes.txt @@ -30,6 +30,7 @@ X kernel facilities (poll, select, etc.) - Exceptions in event-driven code. - SIGPIPE, EPIPE - might have more to do with long-lived processes rather than just event-driven programming, but still something to watch out for... +- You should almost always check the return code of your syscalls to see if they succeeded or not. 7. Promises: - Future @@ -51,6 +52,7 @@ X What is event-driven programming? - C10k problem - EDA (event-driven architecture) - Benefits of Event-driven +- How to debug event-driven code. Traditional programs: - CGI - web server calls your program, and your program does its thing and diff --git a/slides.html b/slides.html index d86ee03..6d589b4 100644 --- a/slides.html +++ b/slides.html @@ -445,6 +445,56 @@ while (1) { - [`Mojo::Reactor::Poll`](https://metacpan.org/source/Mojo::Reactor::Poll) ] +--- +name: not-all-roses +class: center, middle + +![Thorns](img/thorn.jpg) + +## Watch out for the thorns... + +??? +There are some special considerations you need to take when writing event-driven code. + +--- +class: center, middle + +## Exceptions for error handling + +--- +class: center, middle + +### Problem: No exception handler up the call stack + +--- +class: ex-exceptions + +## Rule: Don't die/throw in event handlers. + +-- +### Error callback pattern + +```perl +do_something_asynchronously( + callback => sub { ... }, + on_error => sub { ... }, +); +``` + +--- +class: ex-exceptions + +## Rule: Don't die/throw in event handlers. + +### Use promises + +```perl +my $promise = do_something_asynchronously(); + +$promise->on_done(sub { ... }); +$promise->on_fail(sub { ... }); +``` + --- class: center, middle