make op_create_worker async internally
@@ -37,6 +37,7 @@ use futures::Async;
use futures::Poll;
use futures::Sink;
use futures::Stream;
+use futures::future;
use hyper;
use hyper::rt::Future;
use rand::{thread_rng, Rng};
@@ -2044,7 +2045,6 @@ fn op_create_worker(
let inner = base.inner_as_create_worker().unwrap();
let specifier = inner.specifier().unwrap();
- Box::new(futures::future::result(move || -> OpResult {
let parent_state = state.clone();
let child_state = ThreadSafeState::new(
@@ -2061,13 +2061,12 @@ fn op_create_worker(
js_check(worker.execute("denoMain()"));
js_check(worker.execute("workerMain()"));
- let specifier_url =
- root_specifier_to_url(specifier).map_err(DenoError::from)?;
-
- // TODO(ry) Use execute_mod_async here.
- let result = worker.execute_mod(&specifier_url, false);
- match result {
- Ok(()) => {
+ let op = root_specifier_to_url(specifier)
+ .and_then(|specifier_url| {
+ Ok(
+ worker
+ .execute_mod_async(&specifier_url, false)
+ .and_then(move |worker| {
let mut workers_tl = parent_state.workers.lock().unwrap();
workers_tl.insert(rid, worker.shared());
let builder = &mut FlatBufferBuilder::new();
@@ -2084,11 +2083,19 @@ fn op_create_worker(
..Default::default()
},
))
+ }).map_err(|err| match err {
+ (errors::RustOrJsError::Js(_), _worker) => {
+ errors::worker_init_failed()
}
- Err(errors::RustOrJsError::Js(_)) => Err(errors::worker_init_failed()),
- Err(errors::RustOrJsError::Rust(err)) => Err(err),
- }
- }()))
+ (errors::RustOrJsError::Rust(err), _worker) => err,
+ }),
+ )
+ }).map_err(DenoError::from);
+
+ Box::new(match op {
+ Ok(op) => future::Either::A(op),
+ Err(err) => future::Either::B(future::result(Err(err))),
+ })
}
/// Return when the worker closes
