Skip to content

Commit

Permalink
feat: further more fixes to the lifetime of React
Browse files Browse the repository at this point in the history
  • Loading branch information
ShindouMihou committed Nov 30, 2023
1 parent 2ab7bc9 commit e9ec97f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/main/java/pw/mihou/nexus/features/react/React.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import pw.mihou.nexus.Nexus
import pw.mihou.nexus.configuration.modules.Cancellable
import pw.mihou.nexus.core.assignment.NexusUuidAssigner
import pw.mihou.nexus.features.messages.NexusMessage
import java.time.Instant
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.locks.ReentrantLock
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -44,6 +46,11 @@ class React internal constructor(private val api: DiscordApi, private val render
internal var messageUpdater: MessageUpdater? = null
internal var interactionUpdater: InteractionOriginalResponseUpdater? = null

// Used for debugging purposes
// TODO: Remove once we've identified memory consumption issues.
@Suppress("UNUSED", "PrivatePropertyName")
private val `react$creationDate` = Instant.now()

private var unsubscribe: Unsubscribe = {}
private var component: (Component.() -> Unit)? = null

Expand Down Expand Up @@ -132,8 +139,11 @@ class React internal constructor(private val api: DiscordApi, private val render
*/
internal fun acknowledgeUpdate(message: Message) {
this.resultingMessage = message
messageDeleteListenerManager = this.resultingMessage?.addMessageDeleteListener {
this.destroy()
messageDeleteListenerManager?.remove()
messageDeleteListenerManager = this.resultingMessage?.run {
api.addMessageDeleteListener {
destroy()
}
}
updateSubscribers.forEach {
try {
Expand Down

0 comments on commit e9ec97f

Please sign in to comment.