fix drill-01 exercise-4
continuous-integration/drone/tag Build is passing Details

The server executes the factorial asynchronously
This commit is contained in:
Raffaele Mignone 2020-03-20 11:32:34 +01:00
parent d822faab60
commit a6ae9aa30f
Signed by: norangebit
GPG Key ID: F5255658CB220573
4 changed files with 10 additions and 3 deletions

View File

@ -19,6 +19,7 @@ group = "it.norangeb.unisannio"
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.5")
testCompile("junit", "junit", "4.12")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.7.0-beta2")
}

View File

@ -20,4 +20,7 @@ val clientHandler = {
sps.print("The factorial of $n is $fact")
math.getFactOf(n, aps)
for (i in 0 until 500)
println("other work...")
}

View File

@ -1,6 +1,8 @@
package drills.drill01.exercise4
import drills.drill01.exercise2.PrintService
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.rmi.Remote
import java.rmi.RemoteException
import java.rmi.server.UnicastRemoteObject
@ -17,7 +19,9 @@ class MathImpl : Math, UnicastRemoteObject() {
override fun getFactOf(n: Int): Long = fact(n)
override fun getFactOf(n: Int, ps: PrintService) {
ps.print("The factorial of $n is ${fact(n)}")
GlobalScope.launch {
ps.print("The factorial of $n is ${fact(n)}")
}
}
private fun fact(n: Int): Long {

View File

@ -4,8 +4,7 @@ import util.rmi.Server
fun main() {
Server {
val math: Math =
MathImpl()
val math: Math = MathImpl()
Server.bind(math, "math")
}.start()
}