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/
.kotlin/

View File

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

View File

@ -10,8 +10,12 @@ fun CoroutineScope.LinkedSupervisorJob(
additionalContext: CoroutineContext? = null
) = coroutineContext.LinkedSupervisorJob(additionalContext)
fun CoroutineScope.LinkedSupervisorScope(
fun CoroutineContext.LinkedSupervisorScope(
additionalContext: CoroutineContext? = null
) = 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
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.fsm.common.utils.StateHandlingErrorHandler
import dev.inmo.micro_utils.fsm.common.utils.defaultStateHandlingErrorHandler
@ -118,15 +117,17 @@ open class DefaultStatesMachine <T: State>(
* [launchStateHandling] will returns some [State] then [statesManager] [StatesManager.update] will be used, otherwise
* [StatesManager.endChain].
*/
override fun start(scope: CoroutineScope): Job = scope.launchSafelyWithoutExceptions {
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(this) {
launch { performStateUpdate(Optional.absent(), it, scope.LinkedSupervisorScope()) }
override fun start(scope: CoroutineScope): Job {
val supervisorScope = scope.LinkedSupervisorScope()
supervisorScope.launchSafelyWithoutExceptions {
(statesManager.getActiveStates().asFlow() + statesManager.onStartChain).subscribeSafelyWithoutExceptions(supervisorScope) {
supervisorScope.launch { performStateUpdate(Optional.absent(), it, supervisorScope) }
}
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(this) {
launch { performStateUpdate(Optional.presented(it.first), it.second, scope.LinkedSupervisorScope()) }
statesManager.onChainStateUpdated.subscribeSafelyWithoutExceptions(supervisorScope) {
supervisorScope.launch { performStateUpdate(Optional.presented(it.first), it.second, supervisorScope) }
}
statesManager.onEndChain.subscribeSafelyWithoutExceptions(this) { removedState ->
launch {
statesManager.onEndChain.subscribeSafelyWithoutExceptions(supervisorScope) { removedState ->
supervisorScope.launch {
statesJobsMutex.withLock {
val stateInMap = statesJobs.keys.firstOrNull { stateInMap -> stateInMap == removedState }
if (stateInMap === removedState) {
@ -137,6 +138,9 @@ open class DefaultStatesMachine <T: State>(
}
}
return supervisorScope.coroutineContext.job
}
/**
* Just calls [StatesManager.startChain] of [statesManager]
*/

View File

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