Skip to content

Commit 133a10c

Browse files
authored
Use getOrPut() to resolve race conditon with Links (#26)
1 parent 11c4a59 commit 133a10c

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkClient.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,9 @@ class LavalinkClient(val userId: Long) : Closeable, Disposable {
104104
*/
105105
@JvmOverloads
106106
fun getOrCreateLink(guildId: Long, region: VoiceRegion? = null): Link {
107-
if (!linkMap.containsKey(guildId)) {
108-
val bestNode = loadBalancer.selectNode(region, guildId)
109-
linkMap[guildId] = Link(guildId, bestNode)
107+
return linkMap.getOrPut(guildId) {
108+
Link(guildId, loadBalancer.selectNode(region, guildId))
110109
}
111-
112-
return linkMap[guildId]!!
113110
}
114111

115112
/**

0 commit comments

Comments
 (0)