mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 08:13:47 +00:00
all triggers in behaviour builder now use accumulator flow
This commit is contained in:
parent
5a192b00d4
commit
ad9bc36f8c
@ -144,16 +144,19 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithFlowsUpdatesFilterSe
|
||||
suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
||||
updatesFilter: CustomBehaviourContextAndTypeReceiver<BC, Boolean, Update>?,
|
||||
stopOnCompletion: Boolean = true,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
): T = copy(
|
||||
scope = LinkedSupervisorScope(),
|
||||
scope = scope,
|
||||
updatesFilter = updatesFilter ?.let { _ ->
|
||||
{
|
||||
(this as? BC) ?.run {
|
||||
updatesFilter(it)
|
||||
} ?: true
|
||||
}
|
||||
}
|
||||
},
|
||||
upstreamUpdatesFlow = updatesUpstreamFlow
|
||||
).run {
|
||||
withContext(coroutineContext) {
|
||||
behaviourContextReceiver().also { if (stopOnCompletion) stop() }
|
||||
@ -162,8 +165,10 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
||||
|
||||
suspend fun <T> BehaviourContext.doInSubContext(
|
||||
stopOnCompletion: Boolean = true,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
||||
behaviourContextReceiver: BehaviourContextReceiver<T>
|
||||
) = doInSubContextWithUpdatesFilter(updatesFilter = null, stopOnCompletion, behaviourContextReceiver)
|
||||
) = doInSubContextWithUpdatesFilter(updatesFilter = null, stopOnCompletion, updatesUpstreamFlow, scope, behaviourContextReceiver)
|
||||
|
||||
/**
|
||||
* This method will cancel ALL subsequent contexts, expectations and waiters
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.inmo.tgbotapi.extensions.behaviour_builder.triggers_handling
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptionsAsync
|
||||
import dev.inmo.micro_utils.coroutines.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.*
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.expectations.expectFlow
|
||||
import dev.inmo.tgbotapi.extensions.behaviour_builder.utils.SimpleFilter
|
||||
@ -21,9 +21,12 @@ internal suspend inline fun <BC : BehaviourContext, reified T> BC.on(
|
||||
scope,
|
||||
markerFactory::invoke
|
||||
) { triggerData ->
|
||||
val scope = LinkedSupervisorScope()
|
||||
doInSubContextWithUpdatesFilter(
|
||||
updatesFilter = subcontextUpdatesFilter ?.toOneType(triggerData),
|
||||
stopOnCompletion = false
|
||||
stopOnCompletion = false,
|
||||
updatesUpstreamFlow = allUpdatesFlow.accumulatorFlow(scope),
|
||||
scope = scope
|
||||
) {
|
||||
scenarioReceiver(triggerData)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user