mirror of
https://github.com/InsanusMokrassar/TelegramBotAPI.git
synced 2024-11-22 00:03:48 +00:00
commit
4b8de04380
@ -1,5 +1,11 @@
|
||||
# TelegramBotAPI changelog
|
||||
|
||||
## 18.1.0
|
||||
|
||||
* `BehaviourBuilder`:
|
||||
* Add `createSubContextAndDoSynchronouslyWithUpdatesFilter` as old logic of `createSubContextAndDoWithUpdatesFilter`
|
||||
* `createSubContextAndDoWithUpdatesFilter` has been renamed to `createSubContextAndDoAsynchronouslyWithUpdatesFilter`
|
||||
|
||||
## 18.0.0
|
||||
|
||||
**THIS UPDATE CONTAINS BREAKING CHANGES**
|
||||
|
@ -6,4 +6,4 @@ kotlin.incremental=true
|
||||
kotlin.incremental.js=true
|
||||
|
||||
library_group=dev.inmo
|
||||
library_version=18.0.0
|
||||
library_version=18.1.0
|
||||
|
@ -36,6 +36,10 @@ public final class dev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourConte
|
||||
public static final fun CustomBehaviourContextReceiver (Lkotlin/jvm/functions/Function2;)Lkotlin/jvm/functions/Function2;
|
||||
public static final fun createSubContext (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;
|
||||
public static synthetic fun createSubContext$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlinx/coroutines/CoroutineScope;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;ILjava/lang/Object;)Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;
|
||||
public static final fun createSubContextAndDoAsynchronouslyWithUpdatesFilter (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun createSubContextAndDoAsynchronouslyWithUpdatesFilter$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/coroutines/CoroutineContext;Lkotlinx/coroutines/CoroutineStart;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun createSubContextAndDoSynchronouslyWithUpdatesFilter (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun createSubContextAndDoSynchronouslyWithUpdatesFilter$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun createSubContextAndDoWithUpdatesFilter (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
public static synthetic fun createSubContextAndDoWithUpdatesFilter$default (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Ldev/inmo/tgbotapi/extensions/behaviour_builder/utils/handlers_registrar/TriggersHolder;Lkotlinx/coroutines/flow/Flow;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
|
||||
public static final fun doInContext (Ldev/inmo/tgbotapi/extensions/behaviour_builder/BehaviourContext;Lkotlin/jvm/functions/Function2;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
|
||||
|
@ -11,6 +11,8 @@ import dev.inmo.tgbotapi.updateshandlers.*
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.channels.BufferOverflow
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlin.coroutines.EmptyCoroutineContext
|
||||
|
||||
typealias CustomBehaviourContextReceiver<BC, T> = suspend BC.() -> T
|
||||
typealias BehaviourContextReceiver<T> = CustomBehaviourContextReceiver<BehaviourContext, T>
|
||||
@ -145,9 +147,12 @@ suspend fun <T, BC : BehaviourContext> BC.doInContext(
|
||||
|
||||
/**
|
||||
* Creates new one [BehaviourContext] using [createSubContext] and launches [behaviourContextReceiver] in a new context
|
||||
* using [doInContext]
|
||||
* using [doInContext].
|
||||
*
|
||||
* This action will be executed in **synchronous** manner which means that until the context created with
|
||||
* [createSubContext] will be done this function will not let execution of code continue
|
||||
*/
|
||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(
|
||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoSynchronouslyWithUpdatesFilter(
|
||||
triggersHolder: TriggersHolder = this.triggersHolder,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
@ -161,6 +166,45 @@ suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses [createSubContextAndDoSynchronouslyWithUpdatesFilter], but wrapping it in [async]. That means, that
|
||||
* execution of this function will be **asynchronous** and **will not** block execution of code by default
|
||||
*/
|
||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoAsynchronouslyWithUpdatesFilter(
|
||||
triggersHolder: TriggersHolder = this.triggersHolder,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
context: CoroutineContext = EmptyCoroutineContext,
|
||||
start: CoroutineStart = CoroutineStart.DEFAULT,
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
): Deferred<T> = async(
|
||||
context,
|
||||
start
|
||||
) {
|
||||
createSubContextAndDoSynchronouslyWithUpdatesFilter(
|
||||
triggersHolder,
|
||||
updatesUpstreamFlow,
|
||||
behaviourContextReceiver
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* It is just backward compatibility function which will be removed in next updates.
|
||||
*
|
||||
* Uses [createSubContextAndDoAsynchronouslyWithUpdatesFilter] under the hood with passing of parameters as is
|
||||
*/
|
||||
@Deprecated(
|
||||
"Renamed",
|
||||
ReplaceWith(
|
||||
"createSubContextAndDoAsynchronouslyWithUpdatesFilter(triggersHolder, updatesUpstreamFlow, behaviourContextReceiver = behaviourContextReceiver)",
|
||||
"dev.inmo.tgbotapi.extensions.behaviour_builder.createSubContextAndDoAsynchronouslyWithUpdatesFilter"
|
||||
)
|
||||
)
|
||||
suspend fun <T, BC : BehaviourContext> BC.createSubContextAndDoWithUpdatesFilter(
|
||||
triggersHolder: TriggersHolder = this.triggersHolder,
|
||||
updatesUpstreamFlow: Flow<Update> = allUpdatesFlow,
|
||||
behaviourContextReceiver: CustomBehaviourContextReceiver<BC, T>
|
||||
): Deferred<T> = createSubContextAndDoAsynchronouslyWithUpdatesFilter(triggersHolder, updatesUpstreamFlow, behaviourContextReceiver = behaviourContextReceiver)
|
||||
|
||||
/**
|
||||
* This method will cancel ALL subsequent contexts, expectations and waiters
|
||||
*/
|
||||
|
@ -31,14 +31,14 @@ internal suspend fun <BC : BehaviourContext, T> BC.on(
|
||||
).run {
|
||||
val handler: suspend (Pair<Update, T>) -> Unit = subcontextUpdatesFilter ?.let {
|
||||
{ (update, triggerData) ->
|
||||
createSubContextAndDoWithUpdatesFilter {
|
||||
createSubContextAndDoSynchronouslyWithUpdatesFilter {
|
||||
if (subcontextUpdatesFilter(this, triggerData, update)) {
|
||||
scenarioReceiver(triggerData)
|
||||
}
|
||||
}
|
||||
}
|
||||
} ?: { (_, triggerData) ->
|
||||
createSubContextAndDoWithUpdatesFilter(behaviourContextReceiver = { scenarioReceiver(triggerData) })
|
||||
createSubContextAndDoSynchronouslyWithUpdatesFilter(behaviourContextReceiver = { scenarioReceiver(triggerData) })
|
||||
}
|
||||
markerFactory ?.let {
|
||||
subscribeSafelyWithoutExceptionsAsync(
|
||||
|
Loading…
Reference in New Issue
Block a user