Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Commit 36a1cc9

Browse files
committed
Do not use GlobalScope
1 parent 7fbce0f commit 36a1cc9

File tree

1 file changed

+5
-2
lines changed
  • simplekotlinmail-server/src/main/kotlin/net/axay/simplekotlinmail/server

1 file changed

+5
-2
lines changed

simplekotlinmail-server/src/main/kotlin/net/axay/simplekotlinmail/server/SMTPServer.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.axay.simplekotlinmail.server
22

3-
import kotlinx.coroutines.GlobalScope
3+
import kotlinx.coroutines.CoroutineScope
4+
import kotlinx.coroutines.Dispatchers
45
import kotlinx.coroutines.launch
56
import kotlinx.coroutines.runBlocking
67
import org.subethamail.smtp.server.SMTPServer
@@ -13,6 +14,8 @@ import org.subethamail.smtp.server.SMTPServer
1314
fun smtpServer(port: Int = 25, builder: SMTPServerBuilder.() -> Unit = {}): SMTPServer =
1415
SMTPServerBuilder(port).apply(builder).build()
1516

17+
private val serverScope = CoroutineScope(Dispatchers.IO)
18+
1619
/**
1720
* @param keepAlive true, if the current thread should be kept alive until
1821
* the SMTPServer was shut down
@@ -22,7 +25,7 @@ fun SMTPServer.start(keepAlive: Boolean): SMTPServer {
2225
if (keepAlive)
2326
this@start.start()
2427
else runBlocking {
25-
GlobalScope.launch {
28+
serverScope.launch {
2629
this@start.start()
2730
}.join()
2831
}

0 commit comments

Comments
 (0)