Comments (5)
As a real world example
This:
async fn _join(&self, channel_id: ChannelId) -> Result<()> {
let call = self.bot.songbird.get_or_insert(self.guild_id.into());
{
let mut lock = call.lock().await;
if !lock.is_deaf() {
lock.deafen(true).await?
}
}
let (_, result) = self.bot.songbird.join(self.guild_id, channel_id).await;
result
would turn into this:
async fn _join(&self, channel_id: ChannelId) -> Result<()> {
let call = self.bot.songbird.get_or_insert(self.guild_id.into());
{
let mut lock = call.lock().await;
if !lock.is_deaf() {
lock.deafen(true).await?
}
}
self.bot.songbird.join(channel_id, call).await
}
from songbird.
I agree that being unable to just use ?
to shortcut the return values for these methods is pretty bad. However, I think these suggestions also hurt ergonomics; users are now forced to get a Call
before attempting to join a channel, at which point the Songbird
manager object isn't actually needed any more from a functionality point of view: it just handles consistent lookup if GuildID
s->Call
s, and this API might trick users into trying to make their own standalone Call
s.
There might be cause for moving out the logic in Songbird::join/join_gateway
into an associated function on Call
(namely the risk of deadlock due to lock misuse):
impl Call {
pub fn join_from_lock(self: &Arc<Mutex<Self>>) -> JoinResult<()> {
// Safe handling of lock, await one, unlock, await other...
}
}
...and then pushing users to prefer Songbird::join == Call::join_from_lock > Call::join.
from songbird.
Didn't think about new users fallaciously using Call::standalone()
... I think a safe method on Call
would be equally good although it kinda feels like a hack (why have a safe and an unsafe method?)
from songbird.
It's not an unsafe method; there are just caveats to using a Call
directly, and we can't assume that every user will have it in an Arc<Mutex<...>>
. Join/join_gateway methods which act on the objects themselves cover this niche.
from songbird.
Another option is to not return Call
from songbird.
Related Issues (20)
- How to make Queue Event HOT 1
- How to play/load audio source from base64 HOT 1
- Get songbird instance from external api call HOT 1
- I have tried to work with poise but can't get it to work.
- add custom arg for ffmpeg HOT 5
- thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: Ws(Json(Error("invalid value: integer `18`, expected opcode in [0--9] + [12--13]", line: 1, column: 8)))', src\main.rs:159:218 HOT 4
- Possible memory leak in Serenity 0.12 and Songbird 0.4. HOT 4
- ChildContainers has no audio output HOT 1
- Get aux_metadata from a TrackHandle HOT 2
- The track ends sooner than expected HOT 1
- Event on User join HOT 1
- No voice join event for users HOT 2
- Getting an invalid opcode when attempting to play audio HOT 2
- Playback of tracks stops when moving channel HOT 2
- ogg/vorbis playback fails due to invalid modulo if source_packet.frames() returns 0 HOT 1
- Potential bug when writing to `opus_slot` in `mix_symph_indiv` for Opus Passthrough. HOT 10
- Loops stop working after stopping or playing audio over another HOT 3
- No audio playing from standalone call HOT 6
- Handle YouTube rate limitation HOT 1
- M3U8 support (soundcloud) HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from songbird.