Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gfldex/raku-proc-async-timeout
Run a command asynchronos with a timeout.
https://github.com/gfldex/raku-proc-async-timeout
raku
Last synced: 28 days ago
JSON representation
Run a command asynchronos with a timeout.
- Host: GitHub
- URL: https://github.com/gfldex/raku-proc-async-timeout
- Owner: gfldex
- License: artistic-2.0
- Created: 2017-03-24T00:27:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T19:18:20.000Z (over 4 years ago)
- Last Synced: 2024-11-06T05:44:07.016Z (3 months ago)
- Topics: raku
- Language: Raku
- Homepage:
- Size: 16.6 KB
- Stars: 0
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Proc::Async::Timeout
Run a command asynchronos with a timeout. When the timeout is hit
`X::Proc::Async::Timeout` is thrown and the command is killed.[![Build Status](https://travis-ci.org/gfldex/raku-proc-async-timeout.svg?branch=master)](https://travis-ci.org/gfldex/raku-proc-async-timeout)
## SYNOPSIS
```
use v6.c;use Proc::Async::Timeout;
my $s = Proc::Async::Timeout.new('find', '/home', :enc);
$s.stdout.lines.tap: { .say if .lc.contains(any ) }
$s.stderr.tap: { Nil }await $s.start: timeout => 2;
CATCH {
when X::Proc::Async::Timeout {
say "cought: ", .^name;
say "reporting: ", .Str;
}
when X::Promise::Broken ^ X::Proc::Async::Timeout {
say "something else when wrong";
}
}# OUTPUT:
# cought: X::Proc::Async::Timeout+{X::Promise::Broken}
# reporting: ⟨sleep⟩ timed out after 2 seconds.
```## Methods
Proc::Async::Timeout.start(:$timeout = Inf, |c --> Promise:D)
Executes the stored command and sets a timeout. All additional arguments are
forwarded to `Proc::Async.start`. If the timeout is hit before the command
finished `X::Proc::Async::Timeout` is thrown. Setting `:timeout` to `Inf` will
never throw.## LICENSE
All files (unless noted otherwise) can be used, modified and redistributed
under the terms of the Artistic License Version 2. Examples (in the
documentation, in tests or distributed as separate files) can be considered
public domain.ⓒ2017 Wenzel P. P. Peppmeyer