From af8ff47de129c57dac93defe4a92d44fedcc55fd Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sat, 30 Jul 2016 07:21:15 -0400 Subject: Fix non-thread-safe-cache in example --- examples/05-bash-bot-with-filter.p6 | 12 +++++++----- 1 file 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; 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; } } -- cgit v1.1