Last active
May 6, 2023 15:40
-
-
Save dacr/cf5c43906d032eb819385be215cc7a78 to your computer and use it in GitHub Desktop.
ZIO learning - interrupting a sub command & its process / published by https://github.com/dacr/code-examples-manager #94b93765-4924-4ce4-b8fb-81fd80b27e29/fe3135143f4aaadb58a88a39ab5572a36d9452cf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// summary : ZIO learning - interrupting a sub command & its process | |
// keywords : scala, zio, learning, process, commands, pure-functional, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : 94b93765-4924-4ce4-b8fb-81fd80b27e29 | |
// created-on : 2022-01-15T11:35:16+01:00 | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.2.2" | |
//> using dep "dev.zio::zio:2.0.13" | |
//> using dep "dev.zio::zio-process:0.7.2" | |
// --------------------- | |
import zio.* | |
import zio.process.* | |
object Encapsulated extends ZIOAppDefault: | |
def run = | |
for | |
process <- Command("vmstat", "1").redirectErrorStream(true).run | |
linesFiber <- process.stdout.lines.fork | |
_ <- Clock.sleep(5.seconds) | |
_ <- process.killTree | |
lines <- linesFiber.join | |
_ <- Console.printLine(s"Gotten lines = ${lines.mkString("\n")}") | |
yield () | |
Encapsulated.main(Array.empty) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment