aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZoffix Znet <cpan@zoffix.com>2016-07-30 07:21:15 -0400
committerZoffix Znet <cpan@zoffix.com>2016-07-30 07:21:15 -0400
commitaf8ff47de129c57dac93defe4a92d44fedcc55fd (patch)
treefe3d53c1d1b64595f47135633583ec60a32a6f81
parentee8756a3e043b145e6e3ba893ae02b7309ac5d6c (diff)
Fix non-thread-safe-cache in example
-rw-r--r--examples/05-bash-bot-with-filter.p612
1 files changed, 7 insertions, 5 deletions
diff --git a/examples/05-bash-bot-with-filter.p6 b/examples/05-bash-bot-with-filter.p6
index f3f2c3b..730d9ea 100644
--- a/examples/05-bash-bot-with-filter.p6
+++ b/examples/05-bash-bot-with-filter.p6
@@ -5,15 +5,17 @@ use Pastebin::Shadowcat;
use Mojo::UserAgent:from<Perl5>;
class Bash {
- has @!quotes;
- has $!ua = Mojo::UserAgent.new;
constant $BASH_URL = 'http://bash.org/?random1';
+ constant $cache = Channel.new;
+ has $!ua = Mojo::UserAgent.new;
- method irc-to-me ($ where /bash/) {
- start self!fetch-quotes and @!quotes.shift;
+ multi method irc-to-me ($ where /bash/) {
+ start $cache.poll or do { self!fetch-quotes; $cache.poll };
}
+
method !fetch-quotes {
- @!quotes ||= $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text;
+ $cache.send: $_
+ for $!ua.get($BASH_URL).res.dom.find('.qt').each».all_text;
}
}