From 2cf7611e7c2aa5a6b374a4b89f7c9aa5d84d6e7d Mon Sep 17 00:00:00 2001 From: dakkar Date: Sat, 23 Dec 2017 19:41:39 +0000 Subject: MusicFile is now synchronous --- lib/Ultramarine/Model/MusicFile.pm6 | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/lib/Ultramarine/Model/MusicFile.pm6 b/lib/Ultramarine/Model/MusicFile.pm6 index ec1cbd7..c82d433 100644 --- a/lib/Ultramarine/Model/MusicFile.pm6 +++ b/lib/Ultramarine/Model/MusicFile.pm6 @@ -1,29 +1,15 @@ use v6.d.PREVIEW; use JSON::Fast; -=begin example - -my @files = @*ARGS.map: { Ultramarine::Model::MusicFile.new(path=>$_) }; -my @metadata-p = @filesĀ».metadata; -await Promise.allof(@metadata-p); - -say (@metadata-pĀ».result).perl; - -=end example - class Ultramarine::Model::MusicFile { has $.path is required; - method metadata(-->Promise) { - my $result = Promise.new; - my $proc = Proc::Async.new( - 'avprobe', - '-show_format','-of', 'json', - $.path, - ); - my Str $json-str=''; - $proc.stdout.tap(->$data { $json-str~=$data }); - $proc.stderr.tap(->$err {}); - return $proc.start.then(->$status { from-json $json-str }); + method metadata() { + my $proc = run 'avprobe', '-show_format','-of', 'json', $.path, + :err,:out; + CATCH { when X::Proc::Unsuccessful { .resume } } + my $json-str = $proc.out.slurp(:close); + $proc.err.close(); + return from-json $json-str; } } -- cgit v1.2.3