From 64a52325639053bf8db926eb3b9495e201623d42 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sun, 3 Jun 2018 12:39:43 -0300 Subject: Add new run method. --- lib/Matrix/Client.pm6 | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'lib') diff --git a/lib/Matrix/Client.pm6 b/lib/Matrix/Client.pm6 index 5e4914a..fe3e259 100644 --- a/lib/Matrix/Client.pm6 +++ b/lib/Matrix/Client.pm6 @@ -198,3 +198,31 @@ method upload(IO::Path $path, Str $filename?) { my $data = from-json($res.content); $data // ""; } + +# Misc + +method run(Int :$sleep = 10, :$sync-filter? --> Supply) { + my $s = Supplier.new; + my $supply = $s.Supply; + my $since = ""; + + start { + loop { + my $sync = $.sync(:$since, :$sync-filter); + $since = $sync.next-batch; + say $since; + + for $sync.invited-rooms -> $info { + $s.emit($info); + } + + for $sync.joined-rooms -> $room { + for $room.timeline.events -> $event { + $s.emit($event) + } + } + sleep $sleep; + } + } + $supply +} -- cgit v1.2.3-70-g09d2