From 6a638fd4468736eaf838ee81ee79c93aa258ec26 Mon Sep 17 00:00:00 2001 From: phuvh Date: Tue, 5 Jul 2022 17:28:13 +0700 Subject: [PATCH] =?UTF-8?q?#s=E1=BB=ADa=20m=E1=BB=99t=20s=E1=BB=91=20comme?= =?UTF-8?q?nt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/org/magicghostvu/actor/Behaviors.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/org/magicghostvu/actor/Behaviors.kt b/src/main/kotlin/org/magicghostvu/actor/Behaviors.kt index edd613c..7242d60 100644 --- a/src/main/kotlin/org/magicghostvu/actor/Behaviors.kt +++ b/src/main/kotlin/org/magicghostvu/actor/Behaviors.kt @@ -1,8 +1,6 @@ package org.magicghostvu.actor -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.ObsoleteCoroutinesApi -import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.* import kotlinx.coroutines.channels.ActorScope import kotlinx.coroutines.channels.SendChannel import kotlinx.coroutines.channels.actor @@ -11,7 +9,6 @@ import org.magicghostvu.actor.timer.DelayedMessage import org.magicghostvu.actor.timer.SingleTimerData import org.magicghostvu.actor.timer.TimerManData import org.magicghostvu.mlogger.ActorLogger -import java.lang.management.ManagementFactory object Behaviors { @@ -41,7 +38,7 @@ object Behaviors { // theo mặc định khi actor bị crash nó sẽ stop(cancel) scope đã tạo ra actor // khi actor stop an toàn thì sẽ không affect đến scope ban đầu // nếu createNewScope = true thì sẽ create một scope mới cho actor kèm với supervisor - // actor crash sẽ không gây stop scope ban đầu + // và actor crash sẽ không gây stop scope ban đầu @OptIn(ObsoleteCoroutinesApi::class) private fun CoroutineScope.spawn( debug: Boolean = false, @@ -58,6 +55,7 @@ object Behaviors { } val internalChannel = scopeSpawnActor.actor(capacity = 10000) { + Dispatchers.Unconfined val logger = ActorLogger.logger @@ -177,6 +175,9 @@ object Behaviors { return MActorRef(internalChannel as SendChannel, name) } + // actor mới này nếu stop an toàn thì không affect đến parent + // nếu crash sẽ gây crash parents + // parents stop sẽ stop tất cả các con @OptIn(ObsoleteCoroutinesApi::class) fun ActorScope<*>.spawnChild( debug: Boolean = false,