- 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
- 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
- [`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