]> Dogcows Code - chaz/talk-event-driven-programming-in-perl/blobdiff - slides.html
add SIGPIPE slides
[chaz/talk-event-driven-programming-in-perl] / slides.html
index d86ee03aae1a18331b5ee606173fcdcf85011bb0..51f91018b47b58dc661ea16ec0f31ef6e68920f0 100644 (file)
@@ -445,6 +445,89 @@ 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
+
+## `SIGPIPE`
+
+---
+class: sigpipe
+## `SIGPIPE`
+
+- Sent to your program when it writes to a pipe that was closed.
+
+--
+- Default signal handler terminates the program.
+
+---
+class: ex-sigpipe
+
+## Solution: Ignore `SIGPIPE`
+
+```perl
+$SIG{PIPE} = 'IGNORE';
+```
+
+???
+Some event loops do this for you.
+
+--
+.big[
+Look for `EPIPE` from syscalls (like [`write`](http://man.he.net/man2/write)) instead.
+
+(You *are* checking return codes from your system calls... right?)
+]
+
 ---
 class: center, middle
 
This page took 0.022404 seconds and 4 git commands to generate.