napperley
05/24/2022, 10:45 PM// ...
if (args.isNotEmpty()) args.forEachIndexed { pos, item -> println("Arg ${pos + 1}: $item") }
println("Ping")
println("Pong")
sleep(4u)
println("Another item...")
while (true) {
usleep(500u)
}
The function for running the Serverless Function (on the Serverless Platform side):
private fun CoroutineScope.runFunction(filePath: String, vararg args: String) = launch(context = Dispatchers.Default) {
println("Running Serverless Function...")
val file = openProcess(filePath = filePath, args = args)
file.readLines(5u).forEach { println(it) }
val processName = extractProcessName(filePath)
val pid = fetchLatestPid(processName).toInt()
if (pid > 0) kill(pid, SIGINT)
file.closeProcess()
}
napperley
05/24/2022, 10:53 PM> Task :pipe-reader:runPipe_readerDebugExecutableLinuxX64
Running Serverless Function...
Running Serverless Function...
Arg 1: Testing 1234...
Arg 2: Message A
Arg 3: Hello World! :)
Ping
Pong
Arg 1: Testing 1234...
Arg 2: :)
Ping
Pong
Another item...
BUILD SUCCESSFUL in 6s
If the old Kotlin Native memory model is used then it takes around 10s, and all the Serverless Functions run sequentially instead of being run in parallel.Nick Allen
05/24/2022, 11:47 PMwithTimeout(500L) { // Cancels coroutine on timeout
runInterruptible { // Throws CancellationException if interrupted
doSomethingBlocking() // Interrupted on coroutines cancellation
}
}
napperley
05/25/2022, 1:33 AMrunInterruptible
function is along the lines of what I am looking for. Unfortunately this function isn't available on the Kotlin Native side ☹️ . @elizarovnapperley
05/25/2022, 1:36 AMTijl
05/25/2022, 7:11 AMInterruptedException
, it’s more or less just catch (e: InterruptedException) { throw CancellationException() }
. What would be the equivalent on Native?napperley
05/25/2022, 8:49 PMDALDEI
06/04/2022, 11:01 AMnapperley
06/04/2022, 10:35 PMsuspend fun runProcessTimer(pid: Int, duration: Duration = 3.seconds) = coroutineScope {
launch {
delay(duration)
if (pid > 0 && kill(pid, SIGINT) == 0) println("Process terminated")
}
}
napperley
06/04/2022, 10:37 PMDALDEI
06/07/2022, 3:52 AM>>
>> \<interrupted>
>>
napperley
06/07/2022, 10:09 PMDALDEI
06/09/2022, 11:02 PMDALDEI
06/09/2022, 11:04 PM