Use Arc<> for callback

This commit is contained in:
hodasemi 2018-11-24 12:52:42 +01:00
parent 1fcd593f4d
commit 8d386dadbb
3 changed files with 4 additions and 16 deletions

View file

@ -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 {
($v:expr) => {
if let Err(msg) = $v {

View file

@ -6,7 +6,6 @@ use serenity::voice::LockedAudio;
use std::cell::RefCell;
use std::fs;
use std::ops::{Deref, DerefMut};
use std::rc::Rc;
use std::sync::{Arc, MutexGuard};
use rand::{seq::SliceRandom, thread_rng};
@ -90,7 +89,7 @@ impl Play {
let channel_id = msg.channel_id;
let manager_lock_clone = manager_lock.clone();
Rc::new(move || {
Arc::new(move || {
let callback = match media_clone.next_callback.borrow().deref() {
Some(callback) => callback.clone(),
None => {

View file

@ -4,8 +4,6 @@ use serenity::voice::ffmpeg;
use serenity::voice::LockedAudio;
use std::cell::RefCell;
use std::ops::DerefMut;
use std::rc::Rc;
use std::sync::{Arc, Mutex, MutexGuard};
use super::prelude::*;
@ -18,7 +16,7 @@ pub struct MediaData {
playlist: Mutex<RefCell<Vec<Song>>>,
current_song: Mutex<RefCell<Option<LockedAudio>>>,
song_name: Mutex<RefCell<String>>,
pub next_callback: RefCell<Option<Rc<Fn() -> ()>>>,
pub next_callback: RefCell<Option<Arc<Fn() -> ()>>>,
}
impl MediaData {
@ -86,7 +84,7 @@ impl MediaData {
pub fn start_playing(
mediadata: &Arc<MediaData>,
callback: Rc<Fn() -> ()>,
callback: Arc<Fn() -> ()>,
channel_id: ChannelId,
manager_lock: &Arc<
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
@ -113,7 +111,7 @@ impl MediaData {
manager_lock: &Arc<
serenity::prelude::Mutex<serenity::client::bridge::voice::ClientVoiceManager>,
>,
callback: Rc<Fn() -> ()>,
callback: Arc<Fn() -> ()>,
) {
let mut manager = manager_lock.lock();