File tree Expand file tree Collapse file tree 1 file changed +25
-6
lines changed
io/native/src/main/scala/fs2/io/process Expand file tree Collapse file tree 1 file changed +25
-6
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,8 @@ import java.io.IOException
37
37
import cats .effect .LiftIO
38
38
import cats .effect .IO
39
39
import org .typelevel .scalaccompat .annotation ._
40
+ import scala .concurrent .duration .*
41
+ import cats .effect .implicits .*
40
42
41
43
@ extern
42
44
@ nowarn212(" cat=unused" )
@@ -247,13 +249,30 @@ private[process] trait ProcessesCompanionPlatform extends Processesjvmnative {
247
249
}
248
250
}
249
251
250
- private def fallbackExitValue (pid : pid_t): F [Int ] =
251
- F .blocking {
252
- val status = stackalloc[CInt ]()
253
- val result = waitpid(pid, status, 0 )
254
- if (result == pid) WEXITSTATUS (! status)
255
- else throw new IOException (s " waitpid failed with errno: ${errno.errno}" )
252
+ private def fallbackExitValue (pid : pid_t): F [Int ] = {
253
+ def loop : F [Int ] =
254
+ F .blocking {
255
+ Zone { _ =>
256
+ val status = stackalloc[CInt ]()
257
+ val result = waitpid(pid, status, WNOHANG )
258
+
259
+ if (result == pid) {
260
+ Some (WEXITSTATUS (! status))
261
+ } else if (result == 0 ) None
262
+ else throw new IOException (s " waitpid failed with errno: ${errno.errno}" )
263
+ }
264
+ }.flatMap {
265
+ case Some (code) => F .pure(code)
266
+ case None => F .sleep(10 .millis) >> loop
267
+ }
268
+
269
+ loop.onCancel {
270
+ F .blocking {
271
+ kill(pid, SIGKILL )
272
+ ()
273
+ }
256
274
}
275
+ }
257
276
}
258
277
} else super .forAsync[F ]
259
278
}
You can’t perform that action at this time.
0 commit comments