-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tasks #4
Tasks #4
Conversation
Also, it ended up being easier (mostly due to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great first draft! I have a bunch of nits, but this is very close to being mergeable.
Cargo.toml
Outdated
|
||
[dependencies] | ||
derive_is_enum_variant = "0.1.1" | ||
error-chain = "0.10.0" | ||
futures = "0.1.13" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might as well make this 0.1.15, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, didn't notice there had been new releases since I added this :-P
src/lib.rs
Outdated
use std::sync::Arc; | ||
use std::thread; | ||
|
||
error_chain! { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it'd make sense to switch to derive-error-chain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oo neat, I hadn't seen that before.
I think it is worth doing as a follow up.
src/lib.rs
Outdated
foreign_links { | ||
Io(::std::io::Error) | ||
/// An IO error. | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the way things like this get formatted? It looks quite weird to me. I wasn't able to find other examples, and the other Rust people here also haven't seen anything similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rustfmt
is pretty bad at dealing with things inside macros.
This is error-chain
's fault: it puts the #[attrs]
after the Io(::std::io::Error)
part. Most crates seem to do the unsugared version:
Io(::std::io::Error) #[doc = "An IO error."]
I find this harder to read than the sugared doc comments.
Another reason to switch to derive-error-chain
(and that crate's docs mention this).
} | ||
|
||
errors { | ||
/// Could not create a JavaScript runtime. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these comments are needed because of #![deny(missing_docs)]
? I find it somewhat unfortunate that they don't add any information whatsoever. No, I don't have any suggestions for improving them, but would like to see them removed if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very nice to have when reading the auto-generated docs rather than the source.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I hadn't considered that.
src/lib.rs
Outdated
/// loop. | ||
/// | ||
/// The given `main` JavaScript file will be evaluated as the main task. | ||
pub fn new<P>(main: P) -> Options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the main
arg to a new builder method, e.g. file
? We'll want to support directly executing scripts from strings, and creating JS tasks without any initial script to execute. The latter should probably be the default behavior if file
isn't used. For now, let's just have Starling::run
panic if no file was provided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was imagining the default file
would be repl.js
which drumroll implements a read-eval-print-loop.
And that the explicit_file.unwrap_or(repl_js_file)
bits would be in src/bin/starling.rs
, not the builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, I like the idea of implementing a repl that way!
I still think that we need to have the ability to create a task that just initializes a JS runtime without any source, or that takes a string buffer as the source to evaluate. However, we can always change all this later, so let's leave it as-is for now.
src/lib.rs
Outdated
&self.sync_io_pool | ||
} | ||
|
||
/// Get a handle to the thread pool for performing CPU bound background |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not call these "background tasks": we want to largely eliminate the notion of a main thread after all. Just "task" seems fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CPU bound native tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that works
src/lib.rs
Outdated
} | ||
|
||
/// Send a message to the starling main thread synchronously. | ||
pub fn send_sync(&self, msg: StarlingMessage) -> Result<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need the ability to send sync messages? I'd at least try to get away without it as long as possible. The error message below looks like it could be sent asynchronously?
src/task.rs
Outdated
//! | ||
//! Tasks are **lightweight**. In order to facilitate let-it-fail error handling | ||
//! coupled with supervision hierarchies, idle tasks have little memory | ||
//! overhead, and near no time overhead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize that much of this introductory comment is aspirational right now, but this part seems somewhat farther out than the rest in that it depends on SpiderMonkey stuff. Specifically, at the very least bug 1323066 needs to be done. Perhaps extend the comment to be explicit about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing.
src/task.rs
Outdated
use js::rust::Runtime as JsRuntime; | ||
use std::fmt; | ||
use std::os; | ||
// use std::panic; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, woops :-P
js_file: path::PathBuf, | ||
) -> Result<(TaskHandle, thread::JoinHandle<()>)> { | ||
let (send_handle, recv_handle) = oneshot::channel(); | ||
let starling2 = starling.clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this cannot be inlined in the create_main
call directly? (Mainly asking because I dislike the name.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to separate the concepts of spawning a thread and creating a task, since we intend to have them be different things down the line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand why that needs the starling2
local, but given that this is very much a nit, I also don't feel I have to :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't realize you were specifically referring to starling2
-- my reply was about spawn_main
vs create_main
. This is because the first starling
gets moved into the thread, and StarlingHandle
is not Copy
so we have to explicitly clone it into a new variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, all I meant was to not have this local and do starling.clone()
inline in the function call. Clearly this isn't in any way important, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\o/
Cargo.toml
Outdated
@@ -1,13 +1,34 @@ | |||
[package] | |||
authors = ["Nick Fitzgerald <[email protected]>"] | |||
authors = ["The Starling Project Developers"] | |||
description = "The project that will henceforth be known as `starling`." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to mention this earlier: let's change this to "The Starling JS runtime". Not an ideal description, but I can't come up with anything better that's also concise right now. Proposals welcome!
src/lib.rs
Outdated
@@ -1,21 +1,386 @@ | |||
//! The project that will henceforth be known as `starling`. | |||
|
|||
//! The project that will henceforth be known as Starling. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing here.
This commit sets up the infrastructure such that we can evaluate a JS file and exit zero or non-zero if the JS evals OK or throws an exception respectively.
Builds on top of #3
r? @tschneidereit -- still very much a sketch, but it can evaluate files.