mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-25 19:48:43 +00:00
small refactor
This commit is contained in:
parent
db14eee3b6
commit
2ae105cb15
@ -90,7 +90,7 @@ class DefaultBehaviourContext(
|
|||||||
onBufferOverflow: BufferOverflow,
|
onBufferOverflow: BufferOverflow,
|
||||||
upstreamUpdatesFlow: Flow<Update>?,
|
upstreamUpdatesFlow: Flow<Update>?,
|
||||||
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
updatesFilter: BehaviourContextAndTypeReceiver<Boolean, Update>?
|
||||||
): BehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter)
|
): DefaultBehaviourContext = DefaultBehaviourContext(bot, scope, broadcastChannelsSize, onBufferOverflow, upstreamUpdatesFlow, updatesFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun BehaviourContext(
|
fun BehaviourContext(
|
||||||
@ -116,7 +116,8 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
|||||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||||
scope: CoroutineScope = LinkedSupervisorScope(),
|
scope: CoroutineScope = LinkedSupervisorScope(),
|
||||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||||
): T = copy(
|
): T {
|
||||||
|
val newContext = copy(
|
||||||
scope = scope,
|
scope = scope,
|
||||||
updatesFilter = updatesFilter ?.let { _ ->
|
updatesFilter = updatesFilter ?.let { _ ->
|
||||||
{
|
{
|
||||||
@ -126,9 +127,9 @@ suspend fun <T, BC : BehaviourContext> BC.doInSubContextWithUpdatesFilter(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
upstreamUpdatesFlow = updatesUpstreamFlow
|
upstreamUpdatesFlow = updatesUpstreamFlow
|
||||||
).run {
|
) as BC
|
||||||
withContext(coroutineContext) {
|
return withContext(currentCoroutineContext()) {
|
||||||
(this@run as BC).behaviourContextReceiver().also { if (stopOnCompletion) stop() }
|
newContext.behaviourContextReceiver().also { if (stopOnCompletion) newContext.stop() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user