Skip to content

Commit

Permalink
Deprecate asMono
Browse files Browse the repository at this point in the history
  • Loading branch information
duncte123 committed Jan 4, 2024
1 parent 0aa1a8a commit 68c29a4
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

Feature overview:
- [Uses reactor](https://projectreactor.io/) (please make sure you understand how reactor works)
- Works with any discord library (as long as they allow for sending direct request to discord)
- Load balancing based on server metrics and voice server region.
- Make your own custom load balancers and penalty providers!
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/dev/arbjerg/lavalink/client/LavalinkNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class LavalinkNode(

return rest.getPlayer(guildId)
.map { it.toLavalinkPlayer(this) }
.onErrorResume { createOrUpdatePlayer(guildId).asMono() }
.onErrorResume { createOrUpdatePlayer(guildId) }
.doOnNext {
// Update the player internally upon retrieving it.
playerCache[it.guildId] = it
Expand All @@ -134,7 +134,7 @@ class LavalinkNode(

updateConsumer.accept(update)

return update.asMono()
return update
}

/**
Expand Down
2 changes: 0 additions & 2 deletions src/main/kotlin/dev/arbjerg/lavalink/client/Link.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class Link(
node.removeCachedPlayer(guildId)
newNode.createOrUpdatePlayer(guildId)
.applyBuilder(player.stateToBuilder())
.asMono()
.block()
}

Expand All @@ -64,7 +63,6 @@ class Link(
state = LinkState.CONNECTING
node.createOrUpdatePlayer(guildId)
.setVoiceState(newVoiceState)
.asMono()
.subscribe()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,19 @@ class PlayerUpdateBuilder internal constructor(private val node: LavalinkNode, p
voice = state
)

fun asMono(): Mono<LavalinkPlayer> {
return node.rest.updatePlayer(build(), guildId, noReplace)
@Deprecated(
message = "This method causes improper usage of the reactor system",
replaceWith = ReplaceWith("subscribe()")
)
fun asMono(): Mono<LavalinkPlayer> = this

override fun subscribe(actual: CoreSubscriber<in LavalinkPlayer>) {
node.rest.updatePlayer(build(), guildId, noReplace)
.map { it.toLavalinkPlayer(node) }
.doOnNext {
// Update player in cache
node.playerCache[guildId] = it
}
.subscribe(actual)
}

override fun subscribe(actual: CoreSubscriber<in LavalinkPlayer>) = asMono().subscribe(actual)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LavalinkSocket(private val node: LavalinkNode) : WebSocketListener(), Clos
// Re-create the player on the node.
player.stateToBuilder()
.setNoReplace(false)
.asMono().subscribe()
.subscribe()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/JavaJDAExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
case "pause":
this.client.getLink(event.getGuild().getIdLong())
.getPlayer()
.flatMap((player) -> player.setPaused(!player.getPaused()).asMono())
.flatMap((player) -> player.setPaused(!player.getPaused()))
.subscribe((player) -> {
event.reply("Player has been " + (player.getPaused() ? "paused" : "resumed") + "!").queue();
});
Expand Down
1 change: 0 additions & 1 deletion src/test/kotlin/d4jTestScript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ private fun handleSlash(lavalink: LavalinkClient, event: ChatInputInteractionEve
.get()
val link = lavalink.getLink(event.interaction.guildId.get().asLong())
link.getPlayer().block()!!.setIdentifier(input)
.asMono()
.subscribe()
event.reply("Playing!!").subscribe()
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/kotlin/testScript.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ private fun handleSlash(lavalink: LavalinkClient, event: SlashCommandInteraction
when (item) {
is TrackLoaded -> {
link.createOrUpdatePlayer().setTrack(item.track)
.asMono()
.subscribe {
event.hook.sendMessage("Now playing ${item.track.info.title}!").queue()
}
Expand All @@ -212,7 +211,6 @@ private fun handleSlash(lavalink: LavalinkClient, event: SlashCommandInteraction
val track = item.tracks.first()

link.createOrUpdatePlayer().setTrack(track)
.asMono()
.subscribe {
event.hook.sendMessage("Now playing ${track.info.title}!").queue()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent even
case "pause":
this.client.getLink(event.getGuild().getIdLong())
.getPlayer()
.flatMap((player) -> player.setPaused(!player.getPaused()).asMono())
.flatMap((player) -> player.setPaused(!player.getPaused()))
.subscribe((player) -> {
event.reply("Player has been " + (player.getPaused() ? "paused" : "resumed") + "!").queue();
});
Expand Down

0 comments on commit 68c29a4

Please sign in to comment.