Changed api yet again, slightly nicer now.

This commit is contained in:
ryan voots 2018-06-29 18:17:41 +00:00
parent 5b72b0cd9f
commit eb1d26c6f6
2 changed files with 11 additions and 10 deletions

View file

@ -20,7 +20,7 @@ my $timer = IO::Async::Timer::Periodic->new(
interval => 10, interval => 10,
on_tick => sub { on_tick => sub {
my $fut = UQMI::pop_sms(); my $fut = UQMI::pop_sms();
$fut->on_done(sub { $fut->then(sub {
my $data = shift; my $data = shift;
if ($data) { if ($data) {
@ -28,7 +28,9 @@ my $timer = IO::Async::Timer::Periodic->new(
$from =~ s/\+1//; $from =~ s/\+1//;
return UQMI::send_sms($from, "Command not recognized. Try again you dumbass. ".$contents); return UQMI::send_sms($from, "Command not recognized. Try again you dumbass. ".$contents);
} }
});
return Future->done();
})->get();
} }
); );

View file

@ -83,15 +83,15 @@ sub get_message {
sub pop_sms { sub pop_sms {
my $message_list = _sms_list()->get(); my $message_list = _sms_list()->get();
print "MMM: $message_list\n";
if ($message_list->@*) { if ($message_list->@*) {
my $mid = pop $message_list->@*; my $mid = pop $message_list->@*;
my $fut = get_message($mid); my $fut = get_message($mid);
$fut->on_done(sub { return $fut->then(sub {
return _call_json(qw/--delete-message/, $mid); my $data = shift;
})->on_done(sub {print "Message deleted\n";}); say "Got message data ".$data;
return $fut; _call_plain(qw/--delete-message/, $mid)->get();
return Future->done($data);
});
} else { } else {
return Future->done(); return Future->done();
} }
@ -100,7 +100,6 @@ sub pop_sms {
sub send_sms { sub send_sms {
my ($to, $contents) = @_; my ($to, $contents) = @_;
my $fut = _call_plain(qw/--send-message/, $contents, qw/--send-message-target/, $to); return _call_plain(qw/--send-message/, $contents, qw/--send-message-target/, $to)->on_ready(sub {say "Message sent"});
return $fut;
} }
1; 1;