Introduce TaskOnce

Having both TaskBox and TaskOnce allows us to remove the superfluous inner boxing
from CancellableTask<T>.
This commit is contained in:
Anthony Ramine 2017-09-20 10:37:09 +02:00
parent 52527d6f9d
commit 6c9fb5ae7a
26 changed files with 144 additions and 124 deletions

View file

@ -40,7 +40,7 @@ use std::collections::HashMap;
use std::rc::Rc;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use task::TaskBox;
use task::TaskOnce;
const KEY_CONVERSION_ERROR: &'static str = "This `manufacturerData` key can not be parsed as unsigned short:";
const FILTER_EMPTY_ERROR: &'static str = "'filters' member, if present, must be nonempty to find any devices.";
@ -229,18 +229,17 @@ pub fn response_async<T: AsyncBluetoothListener + DomObject + 'static>(
action: BluetoothResponseResult,
}
impl<T> TaskBox for ListenerTask<T>
impl<T> TaskOnce for ListenerTask<T>
where
T: AsyncBluetoothListener + DomObject,
{
fn run_box(self: Box<Self>) {
let this = *self;
let mut context = this.context.lock().unwrap();
context.response(this.action);
fn run_once(self) {
let mut context = self.context.lock().unwrap();
context.response(self.action);
}
}
let task = box ListenerTask {
let task = ListenerTask {
context: context.clone(),
action: message.to().unwrap(),
};