mirror of
https://github.com/mamoe/mirai.git
synced 2024-12-29 10:00:13 +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?) {
|
||||
if (!this.isActive) return
|
||||
|
||||
if (networkInitialized) {
|
||||
network.close(cause)
|
||||
}
|
||||
|
||||
if (cause == null) {
|
||||
supervisorJob.cancel()
|
||||
} else {
|
||||
supervisorJob.cancel(CancellationException("Bot closed", cause))
|
||||
try {
|
||||
if (networkInitialized) {
|
||||
network.close(cause)
|
||||
}
|
||||
} finally { // ensure CoroutineScope is always closed
|
||||
if (cause == null) {
|
||||
supervisorJob.cancel()
|
||||
} else {
|
||||
supervisorJob.cancel(CancellationException("Bot closed", cause))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user