add .kotlin in gitignore

This commit is contained in:
InsanusMokrassar 2024-06-16 22:27:07 +06:00
parent 5db4c5c717
commit 93b054d55e
5 changed files with 35 additions and 25 deletions

2
.gitignore vendored
View File

@ -17,3 +17,5 @@ publishing.sh
local.* local.*
local/ local/
.kotlin/

View File

@ -8,34 +8,34 @@ fun CoroutineScope.launchSafely(
context: CoroutineContext = EmptyCoroutineContext, context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT, start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler, onException: ExceptionHandler<Unit> = defaultSafelyExceptionHandler,
block: suspend CoroutineScope.() -> Unit block: suspend () -> Unit
) = launch(context, start) { ) = launch(context, start) {
runCatchingSafely(onException) { block() } runCatchingSafely(onException, block = block)
} }
fun CoroutineScope.launchSafelyWithoutExceptions( fun CoroutineScope.launchSafelyWithoutExceptions(
context: CoroutineContext = EmptyCoroutineContext, context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT, start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<Unit?> = defaultSafelyWithoutExceptionHandlerWithNull, onException: ExceptionHandler<Unit?> = defaultSafelyWithoutExceptionHandlerWithNull,
block: suspend CoroutineScope.() -> Unit block: suspend () -> Unit
) = launch(context, start) { ) = launch(context, start) {
runCatchingSafelyWithoutExceptions(onException) { block() } runCatchingSafelyWithoutExceptions(onException, block = block)
} }
fun <T> CoroutineScope.asyncSafely( fun <T> CoroutineScope.asyncSafely(
context: CoroutineContext = EmptyCoroutineContext, context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT, start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<T> = defaultSafelyExceptionHandler, onException: ExceptionHandler<T> = defaultSafelyExceptionHandler,
block: suspend CoroutineScope.() -> T block: suspend () -> T
) = async(context, start) { ) = async(context, start) {
runCatchingSafely(onException) { block() } runCatchingSafely(onException, block = block)
} }
fun <T> CoroutineScope.asyncSafelyWithoutExceptions( fun <T> CoroutineScope.asyncSafelyWithoutExceptions(
context: CoroutineContext = EmptyCoroutineContext, context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT, start: CoroutineStart = CoroutineStart.DEFAULT,
onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull, onException: ExceptionHandler<T?> = defaultSafelyWithoutExceptionHandlerWithNull,
block: suspend CoroutineScope.() -> T block: suspend () -> T
) = async(context, start) { ) = async(context, start) {
runCatchingSafelyWithoutExceptions(onException) { block() } runCatchingSafelyWithoutExceptions(onException, block = block)
} }

View File

@ -10,8 +10,12 @@ fun CoroutineScope.LinkedSupervisorJob(
additionalContext: CoroutineContext? = null additionalContext: CoroutineContext? = null
) = coroutineContext.LinkedSupervisorJob(additionalContext) ) = coroutineContext.LinkedSupervisorJob(additionalContext)
fun CoroutineScope.LinkedSupervisorScope(
fun CoroutineContext.LinkedSupervisorScope(
additionalContext: CoroutineContext? = null additionalContext: CoroutineContext? = null
) = CoroutineScope( ) = CoroutineScope(
coroutineContext + LinkedSupervisorJob(additionalContext) this + LinkedSupervisorJob(additionalContext)
) )
fun CoroutineScope.LinkedSupervisorScope(
additionalContext: CoroutineContext? = null
) = coroutineContext.LinkedSupervisorScope(additionalContext)

View File

@ -1,7 +1,6 @@
package dev.inmo.micro_utils.fsm.common package dev.inmo.micro_utils.fsm.common
import dev.inmo.micro_utils.common.Optional import dev.inmo.micro_utils.common.Optional
import dev.inmo.micro_utils.common.onPresented
import dev.inmo.micro_utils.coroutines.* import dev.inmo.micro_utils.coroutines.*
import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler import dev.inmo.micro_utils.fsm.common.utils.StateHandlingErrorHandler
import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler
@ -118,23 +117,28 @@ open class DefaultStatesMachine <T: State>(
* [launchStateHandling] will returns some [State] then [statesManager] [StatesManager.update] will be used, otherwise * [launchStateHandling] will returns some [State] then [statesManager] [StatesManager.update] will be used, otherwise
* [StatesManager.endChain]. * [StatesManager.endChain].
*/ */
override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions { override fun start(scope: CoroutineScope): Job {
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(this) { val supervisorScope = scope.LinkedSupervisorScope()
launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) } supervisorScope.launchSafelyWithoutExceptions {
} (statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(supervisorScope) {
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) { supervisorScope.launch { performStateUpdate(Optional.absent(), it, supervisorScope) }
launch { performStateUpdate(Optional.presented(it.first), it.second, scope.LinkedSupervisorScope()) } }
} statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(supervisorScope) {
statesManager.onEndChain.subscribeSafelyWithoutExceptions(this) { removedState -> supervisorScope.launch { performStateUpdate(Optional.presented(it.first), it.second, supervisorScope) }
launch { }
statesJobsMutex.withLock { statesManager.onEndChain.subscribeSafelyWithoutExceptions(supervisorScope) { removedState ->
val stateInMap = statesJobs.keys.firstOrNull { stateInMap -> stateInMap == removedState } supervisorScope.launch {
if (stateInMap === removedState) { statesJobsMutex.withLock {
statesJobs[stateInMap] ?.cancel() val stateInMap = statesJobs.keys.firstOrNull { stateInMap -> stateInMap == removedState }
if (stateInMap === removedState) {
statesJobs[stateInMap] ?.cancel()
}
} }
} }
} }
} }
return supervisorScope.coroutineContext.job
} }
/** /**

View File

@ -41,7 +41,7 @@ class TemporalFilesRoutingConfigurator(
filesMutex: Mutex, filesMutex: Mutex,
onNewFileFlow: Flow<TemporalFileId> onNewFileFlow: Flow<TemporalFileId>
): Job = scope.launchSafelyWithoutExceptions { ): Job = scope.launchSafelyWithoutExceptions {
while (isActive) { while (currentCoroutineContext().isActive) {
val filesWithCreationInfo = filesMap.mapNotNull { (fileId, file) -> val filesWithCreationInfo = filesMap.mapNotNull { (fileId, file) ->
fileId to ((Files.getAttribute(file.toPath(), "creationTime") as? FileTime) ?.toMillis() ?: return@mapNotNull null) fileId to ((Files.getAttribute(file.toPath(), "creationTime") as? FileTime) ?.toMillis() ?: return@mapNotNull null)
} }