aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/task_source/networking.rs
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2016-10-13 17:41:48 -0700
committerKeith Yeung <kungfukeith11@gmail.com>2016-11-11 14:50:42 -0800
commit72cb856e31eecd9310cbcf3745baa16fd77dc8e9 (patch)
treefed4bcd6568d59fa5109fbd4d5230e1cdf8589b5 /components/script/task_source/networking.rs
parentd99d26cf1fc3cc2199cc8d84817c0b505e9634d2 (diff)
downloadservo-72cb856e31eecd9310cbcf3745baa16fd77dc8e9.tar.gz
servo-72cb856e31eecd9310cbcf3745baa16fd77dc8e9.zip
Properly implement TaskSource for NetworkingTaskSource
Diffstat (limited to 'components/script/task_source/networking.rs')
-rw-r--r--components/script/task_source/networking.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/components/script/task_source/networking.rs b/components/script/task_source/networking.rs
index 4f85ac6c3e6..8306a4789bb 100644
--- a/components/script/task_source/networking.rs
+++ b/components/script/task_source/networking.rs
@@ -2,19 +2,32 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use script_runtime::{CommonScriptMsg, ScriptChan};
-use script_thread::MainThreadScriptMsg;
-use std::sync::mpsc::Sender;
+use script_runtime::{CommonScriptMsg, ScriptChan, ScriptThreadEventCategory};
+use script_thread::{Runnable, RunnableWrapper};
+use task_source::TaskSource;
#[derive(JSTraceable)]
-pub struct NetworkingTaskSource(pub Sender<MainThreadScriptMsg>);
+pub struct NetworkingTaskSource(pub Box<ScriptChan + Send + 'static>);
-impl ScriptChan for NetworkingTaskSource {
- fn send(&self, msg: CommonScriptMsg) -> Result<(), ()> {
- self.0.send(MainThreadScriptMsg::Common(msg)).map_err(|_| ())
+impl Clone for NetworkingTaskSource {
+ fn clone(&self) -> NetworkingTaskSource {
+ NetworkingTaskSource(self.0.clone())
}
+}
+
+impl TaskSource for NetworkingTaskSource {
+ fn queue_with_wrapper<T>(&self,
+ msg: Box<T>,
+ wrapper: &RunnableWrapper)
+ -> Result<(), ()>
+ where T: Runnable + Send + 'static {
+ self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent,
+ wrapper.wrap_runnable(msg)))
+ }
+}
- fn clone(&self) -> Box<ScriptChan + Send> {
- box NetworkingTaskSource((&self.0).clone())
+impl NetworkingTaskSource {
+ pub fn queue_wrapperless<T: Runnable + Send + 'static>(&self, msg: Box<T>) -> Result<(), ()> {
+ self.0.send(CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::NetworkEvent, msg))
}
}