mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-17 09:12:59 +08:00
[core] Ensure Bot's CoroutineScope is always cancelled on Bot.close
if network.close
threw an exception
This commit is contained in:
parent
38162db477
commit
2252683cee
@ -110,14 +110,16 @@ internal abstract class AbstractBot constructor(
|
|||||||
override fun close(cause: Throwable?) {
|
override fun close(cause: Throwable?) {
|
||||||
if (!this.isActive) return
|
if (!this.isActive) return
|
||||||
|
|
||||||
if (networkInitialized) {
|
try {
|
||||||
network.close(cause)
|
if (networkInitialized) {
|
||||||
}
|
network.close(cause)
|
||||||
|
}
|
||||||
if (cause == null) {
|
} finally { // ensure CoroutineScope is always closed
|
||||||
supervisorJob.cancel()
|
if (cause == null) {
|
||||||
} else {
|
supervisorJob.cancel()
|
||||||
supervisorJob.cancel(CancellationException("Bot closed", cause))
|
} else {
|
||||||
|
supervisorJob.cancel(CancellationException("Bot closed", cause))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user