Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use Supply.on-demand
  • Loading branch information
skaji committed Aug 7, 2016
1 parent 813ec1a commit f8c94bf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 8 additions & 2 deletions example.p6
@@ -1,11 +1,17 @@
#!/usr/bin/env perl6
use v6;
use lib "lib", "../lib";
use lib "lib";
use MetaCPAN::Favorite;

my $metacpan = MetaCPAN::Favorite.new(cache => "./cache.txt");
# unlink cache first for test
my $cache = "./cache.txt";
$cache.IO.unlink if $cache.IO.e;

my $metacpan = MetaCPAN::Favorite.new(:$cache);
my $favorite = Supply.interval(60).map({ $metacpan.Supply }).flat;

# my $favorite = $metacpan.Supply; # only once

sub tweet($msg) { note $msg }

react {
Expand Down
9 changes: 4 additions & 5 deletions lib/MetaCPAN/Favorite.pm6
Expand Up @@ -34,13 +34,13 @@ has $.cache;
has %.seen;

method Supply {
supply {
Supply.on-demand: -> $s {
self.load;
my @fav = await self.get-new-favorite;
@fav = await @fav.map: -> $f {
await @fav.map: -> $f {
self.get-user-name($f<user>).then: -> $p {
my $user = $p.result;
%(
$s.emit: %(
name => $f<name>,
date => $f<date>,
user => $user,
Expand All @@ -49,8 +49,7 @@ method Supply {
};
};
self.save;
emit $_ for @fav;
done;
$s.done;
};
}

Expand Down

0 comments on commit f8c94bf

Please sign in to comment.