Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed ScriptChan in constellation to EventLoop.
- Loading branch information
Alan Jeffrey
committed
Dec 15, 2016
1 parent
01b6ad5
commit e945e38
Showing
4 changed files
with
100 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* 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/. */ | ||
|
||
//! This module contains the `EventLoop` type, which is the constellation's | ||
//! view of a script thread. When an `EventLoop` is dropped, an `ExitScriptThread` | ||
//! message is sent to the script thread, asking it to shut down. | ||
|
||
use ipc_channel::ipc::IpcSender; | ||
use script_traits::ConstellationControlMsg; | ||
use std::io::Error as IOError; | ||
use std::marker::PhantomData; | ||
use std::rc::Rc; | ||
|
||
/// https://html.spec.whatwg.org/multipage/#event-loop | ||
pub struct EventLoop { | ||
script_chan: IpcSender<ConstellationControlMsg>, | ||
dont_send_or_sync: PhantomData<Rc<()>>, | ||
} | ||
|
||
impl Drop for EventLoop { | ||
fn drop(&mut self) { | ||
let _ = self.script_chan.send(ConstellationControlMsg::ExitScriptThread); | ||
} | ||
} | ||
|
||
impl EventLoop { | ||
/// Create a new event loop from the channel to its script thread. | ||
pub fn new(script_chan: IpcSender<ConstellationControlMsg>) -> Rc<EventLoop> { | ||
Rc::new(EventLoop { | ||
script_chan: script_chan, | ||
dont_send_or_sync: PhantomData, | ||
}) | ||
} | ||
|
||
/// Send a message to the event loop. | ||
pub fn send(&self, msg: ConstellationControlMsg) -> Result<(), IOError> { | ||
self.script_chan.send(msg) | ||
} | ||
|
||
/// The underlying channel to the script thread. | ||
pub fn sender(&self) -> IpcSender<ConstellationControlMsg> { | ||
self.script_chan.clone() | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.