1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-22 16:23:48 +00:00
This commit is contained in:
InsanusMokrassar 2020-05-17 15:09:48 +06:00
parent 9307582654
commit 006251ed07

View File

@ -77,7 +77,6 @@ fun startListenWebhooks(
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
block: UpdateReceiver<Update> block: UpdateReceiver<Update>
): ApplicationEngine { ): ApplicationEngine {
lateinit var engine: ApplicationEngine
val env = applicationEngineEnvironment { val env = applicationEngineEnvironment {
module { module {
@ -103,10 +102,10 @@ fun startListenWebhooks(
} }
} }
engine = embeddedServer(engineFactory, env)
engine.start(false)
return engine return embeddedServer(engineFactory, env).also {
it.start(false)
}
} }
private suspend fun RequestsExecutor.internalSetWebhookInfoAndStartListenWebhooks( private suspend fun RequestsExecutor.internalSetWebhookInfoAndStartListenWebhooks(
@ -119,14 +118,10 @@ private suspend fun RequestsExecutor.internalSetWebhookInfoAndStartListenWebhook
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
block: UpdateReceiver<Update> block: UpdateReceiver<Update>
): Job { ): ApplicationEngine {
return try { return try {
execute(setWebhookRequest) execute(setWebhookRequest)
val engine = startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, block) startListenWebhooks(listenPort, engineFactory, exceptionsHandler, listenHost, listenRoute, privateKeyConfig, scope, block)
scope.launch {
engine.environment.parentCoroutineContext[Job] ?.join()
engine.stop(1000, 5000)
}
} catch (e: Exception) { } catch (e: Exception) {
throw e throw e
} }
@ -154,7 +149,7 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
block: UpdateReceiver<Update> block: UpdateReceiver<Update>
): Job = internalSetWebhookInfoAndStartListenWebhooks( ): ApplicationEngine = internalSetWebhookInfoAndStartListenWebhooks(
listenPort, listenPort,
engineFactory, engineFactory,
setWebhookRequest as Request<Boolean>, setWebhookRequest as Request<Boolean>,
@ -188,7 +183,7 @@ suspend fun RequestsExecutor.setWebhookInfoAndStartListenWebhooks(
privateKeyConfig: WebhookPrivateKeyConfig? = null, privateKeyConfig: WebhookPrivateKeyConfig? = null,
scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()), scope: CoroutineScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher()),
block: UpdateReceiver<Update> block: UpdateReceiver<Update>
): Job = internalSetWebhookInfoAndStartListenWebhooks( ): ApplicationEngine = internalSetWebhookInfoAndStartListenWebhooks(
listenPort, listenPort,
engineFactory, engineFactory,
setWebhookRequest as Request<Boolean>, setWebhookRequest as Request<Boolean>,