Send AsyncJobHandler as a MainThreadTask

This commit is contained in:
Anthony Ramine 2017-09-16 15:36:10 +02:00
parent 4a39631eaf
commit 9a267e53fe
2 changed files with 20 additions and 2 deletions

View file

@ -133,8 +133,10 @@ impl JobQueue {
if job_queue.is_empty() {
let scope_url = job.scope_url.clone();
job_queue.push(job);
let run_job_handler = box AsyncJobHandler::new(scope_url);
let _ = script_thread.dom_manipulation_task_source().queue(run_job_handler, global);
let _ = script_thread.dom_manipulation_task_source().queue_main_thread_task(
box AsyncJobHandler::new(scope_url),
global,
);
debug!("queued task to run newly-queued job");
} else {
// Step 2

View file

@ -6,6 +6,7 @@ use dom::bindings::inheritance::Castable;
use dom::bindings::refcounted::Trusted;
use dom::event::{EventBubbles, EventCancelable, EventTask, SimpleEventTask};
use dom::eventtarget::EventTarget;
use dom::globalscope::GlobalScope;
use dom::window::Window;
use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory};
use script_thread::{MainThreadScriptMsg, Task, TaskCanceller};
@ -42,6 +43,21 @@ impl TaskSource for DOMManipulationTaskSource {
}
impl DOMManipulationTaskSource {
pub fn queue_main_thread_task<T>(
&self,
task: Box<T>,
global: &GlobalScope,
) -> Result<(), ()>
where
T: Task + Send + 'static,
{
let msg = MainThreadScriptMsg::MainThreadTask(
ScriptThreadEventCategory::ScriptEvent,
global.task_canceller().wrap_task(task),
);
self.0.send(msg).map_err(|_| ())
}
pub fn queue_event(&self,
target: &EventTarget,
name: Atom,