Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
biopet.biopet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Mirrors
biopet.biopet
Commits
dea3adbb
Commit
dea3adbb
authored
Apr 01, 2017
by
Peter van 't Hof
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Style fixes
parent
e596e530
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
36 deletions
+28
-36
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/process/AsyncProcess.scala
...cala/nl/lumc/sasc/biopet/utils/process/AsyncProcess.scala
+28
-36
No files found.
biopet-utils/src/main/scala/nl/lumc/sasc/biopet/utils/process/AsyncProcess.scala
View file @
dea3adbb
...
...
@@ -17,8 +17,8 @@ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
import
scala.concurrent.
{
ExecutionContext
,
Future
,
Promise
}
import
scala.sys.process.
{
Process
,
ProcessLogger
}
import
scala.concurrent.
{
ExecutionContext
,
Future
,
Promise
}
import
scala.sys.process.
{
Process
,
ProcessLogger
}
import
scala.util.Try
object
Sys
extends
Sys
{
...
...
@@ -28,38 +28,37 @@ object Sys extends Sys {
type
ExecResult
=
(
ExitValue
,
Stdout
,
Stderr
)
trait
AsyncExecResult
{
/**
* @see [[scala.concurrent.Future#map]]
*/
* @see [[scala.concurrent.Future#map]]
*/
def
map
[
T
](
f
:
ExecResult
=>
T
)
:
Future
[
T
]
/**
* @see [[scala.concurrent.Future#foreach]]
*/
* @see [[scala.concurrent.Future#foreach]]
*/
def
foreach
(
f
:
ExecResult
=>
Unit
)
:
Unit
/**
* @see [[scala.concurrent.Future#onComplete]]
*/
* @see [[scala.concurrent.Future#onComplete]]
*/
def
onComplete
[
T
](
pf
:
Try
[
ExecResult
]
=>
T
)
:
Unit
/**
* cancels the running process
*/
* cancels the running process
*/
def
cancel
()
:
Unit
/**
* check if the process is still running
* @return `true` if the process is already completed, `false` otherwise
*/
* check if the process is still running
* @return `true` if the process is already completed, `false` otherwise
*/
def
isRunning
:
Boolean
/**
* the underlying future
* @return the future, in which the process runs
*/
* the underlying future
* @return the future, in which the process runs
*/
def
get
:
Future
[
ExecResult
]
}
...
...
@@ -68,19 +67,17 @@ object Sys extends Sys {
case
class
ExecutionCanceled
(
msg
:
String
)
extends
Exception
(
msg
)
}
trait
Sys
{
import
Sys._
def
exec
(
cmd
:
String
)
:
ExecResult
=
exec
(
cmd
.
split
(
" "
))
/**
* executes the cmd and blocks until the command exits.
*
* @return {{{(ExitValue, Stdout, Stderr)}}}
* <pre>if the executable is unable to start, (-1, "", stderr) are returned</pre>
*/
* executes the cmd and blocks until the command exits.
*
* @return {{{(ExitValue, Stdout, Stderr)}}}
* <pre>if the executable is unable to start, (-1, "", stderr) are returned</pre>
*/
def
exec
(
cmd
:
Seq
[
String
])
:
ExecResult
=
{
val
stdout
=
new
OutputSlurper
val
stderr
=
new
OutputSlurper
...
...
@@ -89,22 +86,19 @@ trait Sys {
val
proc
=
Process
(
cmd
).
run
(
ProcessLogger
(
stdout
.
appendLine
,
stderr
.
appendLine
))
proc
.
exitValue
()
}.
map
((
_
,
stdout
.
get
,
stderr
.
get
))
.
recover
{
.
recover
{
case
t
=>
(-
1
,
""
,
t
.
getMessage
)
}.
get
}
def
execAsync
(
cmd
:
String
)(
implicit
ec
:
ExecutionContext
)
:
AsyncExecResult
=
execAsync
(
cmd
.
split
(
" "
))(
ec
)
/**
* executes the cmd asynchronous
* @see scala.concurrent.Future.map
*
* @return [[AsyncExecResult]]
*/
* executes the cmd asynchronous
* @see scala.concurrent.Future.map
*
* @return [[AsyncExecResult]]
*/
def
execAsync
(
cmd
:
Seq
[
String
])(
implicit
ec
:
ExecutionContext
)
:
AsyncExecResult
=
{
new
AsyncExecResult
{
val
(
fut
,
cancelFut
)
=
runAsync
(
cmd
)
...
...
@@ -123,7 +117,6 @@ trait Sys {
}
}
// helper for 'execAsync' - runs the given cmd asynchronous.
// returns a tuple with: (the running process in a future, function to cancel the running process)
private
def
runAsync
(
cmd
:
Seq
[
String
])(
implicit
ec
:
ExecutionContext
)
:
(
Future
[
ExecResult
],
Cancelable
)
=
{
...
...
@@ -153,5 +146,4 @@ trait Sys {
def
get
:
String
=
sb
.
toString
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment