Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix .done
  • Loading branch information
zoffixznet committed Oct 16, 2017
1 parent 1f9a010 commit 13cf8cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/Reminders.pm6
Expand Up @@ -4,7 +4,8 @@ use DBIish;

has $!db;
has $!supplier = Supplier::Preserving.new;
has $.waiting = 0;
has $!waiting = 0;
has $!done = False;

class Rem {
trusts Reminders;
Expand Down Expand Up @@ -43,8 +44,8 @@ submethod TWEAK (IO() :$db-file = 'reminders.sqlite.db') {
else {
$!waiting++;
Promise.at($rem.when).then: {
$!waiting--;
$!supplier.emit: $rem.mark-seen
$!supplier.emit: $rem.mark-seen;
$!supplier.done if $!done and not --$!waiting;
}
}
}
Expand All @@ -57,6 +58,7 @@ multi method add (
Str:D :$where = '',
Instant(Any:D) :$when! where DateTime|Instant
) {
$!done and die 'Cannot add more reminders to Reminders object that was .done';
$!db.do:
INSERT INTO reminders ("who", "what", "where", "when", "created")
VALUES (?, ?, ?, ?, ?)
Expand All @@ -78,8 +80,8 @@ multi method add (
else {
$!waiting++;
Promise.at($rem.when).then: {
$!waiting--;
$!supplier.emit: $rem.mark-seen
$!supplier.emit: $rem.mark-seen;
$!supplier.done if $!done and not --$!waiting;
}
}
}
Expand All @@ -100,7 +102,7 @@ method all (:$all) {
}
}

method close { $!supplier.done }
method done { $!waiting ?? ($!done = True) !! $!supplier.done }

method mark-seen (Rem $rem) {
$!db.do: UPDATE reminders SET seen = 1 WHERE id = ?, $rem.id;
Expand Down

0 comments on commit 13cf8cd

Please sign in to comment.