Use Arc<> for callback
This commit is contained in:
parent
1fcd593f4d
commit
8d386dadbb
3 changed files with 4 additions and 16 deletions
|
@ -46,15 +46,6 @@ macro_rules! display_error {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! check_option {
|
|
||||||
($v:expr) => {
|
|
||||||
match $v {
|
|
||||||
Some(t) => t,
|
|
||||||
None => return,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! print_error {
|
macro_rules! print_error {
|
||||||
($v:expr) => {
|
($v:expr) => {
|
||||||
if let Err(msg) = $v {
|
if let Err(msg) = $v {
|
||||||
|
|
|
@ -6,7 +6,6 @@ use serenity::voice::LockedAudio;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::{Arc, MutexGuard};
|
use std::sync::{Arc, MutexGuard};
|
||||||
|
|
||||||
use rand::{seq::SliceRandom, thread_rng};
|
use rand::{seq::SliceRandom, thread_rng};
|
||||||
|
@ -90,7 +89,7 @@ impl Play {
|
||||||
let channel_id = msg.channel_id;
|
let channel_id = msg.channel_id;
|
||||||
let manager_lock_clone = manager_lock.clone();
|
let manager_lock_clone = manager_lock.clone();
|
||||||
|
|
||||||
Rc::new(move || {
|
Arc::new(move || {
|
||||||
let callback = match media_clone.next_callback.borrow().deref() {
|
let callback = match media_clone.next_callback.borrow().deref() {
|
||||||
Some(callback) => callback.clone(),
|
Some(callback) => callback.clone(),
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -4,8 +4,6 @@ use serenity::voice::ffmpeg;
|
||||||
use serenity::voice::LockedAudio;
|
use serenity::voice::LockedAudio;
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::ops::DerefMut;
|
|
||||||
use std::rc::Rc;
|
|
||||||
use std::sync::{Arc, Mutex, MutexGuard};
|
use std::sync::{Arc, Mutex, MutexGuard};
|
||||||
|
|
||||||
use super::prelude::*;
|
use super::prelude::*;
|
||||||
|
@ -18,7 +16,7 @@ pub struct MediaData {
|
||||||
playlist: Mutex<RefCell<Vec<Song>>>,
|
playlist: Mutex<RefCell<Vec<Song>>>,
|
||||||
current_song: Mutex<RefCell<Option<LockedAudio>>>,
|
current_song: Mutex<RefCell<Option<LockedAudio>>>,
|
||||||
song_name: Mutex<RefCell<String>>,
|
song_name: Mutex<RefCell<String>>,
|
||||||
pub next_callback: RefCell<Option<Rc<Fn() -> ()>>>,
|
pub next_callback: RefCell<Option<Arc<Fn() -> ()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MediaData {
|
impl MediaData {
|
||||||
|
@ -86,7 +84,7 @@ impl MediaData {
|
||||||
|
|
||||||
pub fn start_playing(
|
pub fn start_playing(
|
||||||
mediadata: &Arc<MediaData>,
|
mediadata: &Arc<MediaData>,
|
||||||
callback: Rc<Fn() -> ()>,
|
callback: Arc<Fn() -> ()>,
|
||||||
channel_id: ChannelId,
|
channel_id: ChannelId,
|
||||||
manager_lock: &Arc<
|
manager_lock: &Arc<
|
||||||
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
||||||
|
@ -113,7 +111,7 @@ impl MediaData {
|
||||||
manager_lock: &Arc<
|
manager_lock: &Arc<
|
||||||
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
|
||||||
>,
|
>,
|
||||||
callback: Rc<Fn() -> ()>,
|
callback: Arc<Fn() -> ()>,
|
||||||
) {
|
) {
|
||||||
let mut manager = manager_lock.lock();
|
let mut manager = manager_lock.lock();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue