Skip to content
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

Web workers #1993

Merged
merged 27 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6481082
Web workers pass 1
afinch7 Mar 23, 2019
368bbfd
Make linter happy
afinch7 Mar 23, 2019
d28a44d
fmt
afinch7 Mar 23, 2019
84e56d8
Refactored the way worker polling is scheduled and errors are handled.
afinch7 Mar 25, 2019
df12a00
Some cleanup and handle worker close on host end.
afinch7 Mar 26, 2019
99f6db1
Merge branch 'master' into web_workers
afinch7 Mar 26, 2019
a1b048c
Share the worker future as a Shared
afinch7 Mar 26, 2019
4f52d6b
Merge branch 'web_workers' of https://github.com/afinch7/deno into we…
afinch7 Mar 26, 2019
8d30513
Fixed some merge issues and added a worker test
afinch7 Mar 26, 2019
ec2149b
compile_sync returns errors now
afinch7 Mar 27, 2019
2103d32
Refactored compile_sync again
afinch7 Mar 27, 2019
1a6be92
fixed bugs and moved compiler error exit back to compile_sync
afinch7 Mar 27, 2019
4eb80ab
lots of comments for compile_sync
afinch7 Mar 28, 2019
1e2c184
refactored compile_sync again to use a future that is less blocking.
afinch7 Mar 28, 2019
cfd3289
Merge branch 'master' into web_workers
afinch7 Mar 28, 2019
e245db1
enable debug to find this problem
afinch7 Mar 28, 2019
58de310
remove old comments
afinch7 Mar 28, 2019
e6a3bab
maybe same tokio runtime for all compiler tasks?
afinch7 Mar 28, 2019
fa72bc9
remove debug from tests
afinch7 Mar 28, 2019
32d7ad4
worker ts lib
afinch7 Mar 30, 2019
a9c8271
requested change: workers test assert
afinch7 Mar 31, 2019
5b101a8
renamed WebWorkerBehavior to UserWorkerBehaivor and moved to workers.rs
afinch7 Mar 31, 2019
8388fa2
Merge remote-tracking branch 'upstream/master' into web_workers
afinch7 Mar 31, 2019
53fcd75
fixed remaining merge issues
afinch7 Mar 31, 2019
6e173b8
remove thread spawn from worker tests
afinch7 Mar 31, 2019
5815927
removed worker specific snapshot/bundle
afinch7 Apr 1, 2019
b0881d4
forgot to remove the startup data function
afinch7 Apr 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
renamed WebWorkerBehavior to UserWorkerBehaivor and moved to workers.rs
  • Loading branch information
afinch7 committed Mar 31, 2019
commit 5b101a8b29d4993a7007ef58cc0727495b975034
10 changes: 5 additions & 5 deletions cli/isolate_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::global_timer::GlobalTimer;
use crate::modules::Modules;
use crate::permissions::DenoPermissions;
use crate::resources::ResourceId;
use crate::web_worker_behavior::WebWorkerBehavior;
use crate::workers::UserWorkerBehavior;
use crate::workers::Worker;
use deno_core::Buf;
use futures::future::Shared;
Expand All @@ -21,8 +21,8 @@ use std::sync::Mutex;
pub type WorkerSender = async_mpsc::Sender<Buf>;
pub type WorkerReceiver = async_mpsc::Receiver<Buf>;
pub type WorkerChannels = (WorkerSender, WorkerReceiver);
pub type WebWorkerTable =
HashMap<ResourceId, Shared<Worker<WebWorkerBehavior>>>;
pub type UserWorkerTable =
HashMap<ResourceId, Shared<Worker<UserWorkerBehavior>>>;

// AtomicU64 is currently unstable
#[derive(Default)]
Expand All @@ -49,7 +49,7 @@ pub struct IsolateState {
pub modules: Mutex<Modules>,
pub worker_channels: Option<Mutex<WorkerChannels>>,
pub global_timer: Mutex<GlobalTimer>,
pub workers: Mutex<WebWorkerTable>,
pub workers: Mutex<UserWorkerTable>,
pub is_worker: bool,
}

Expand All @@ -71,7 +71,7 @@ impl IsolateState {
modules: Mutex::new(Modules::new()),
worker_channels: worker_channels.map(Mutex::new),
global_timer: Mutex::new(GlobalTimer::new()),
workers: Mutex::new(WebWorkerTable::new()),
workers: Mutex::new(UserWorkerTable::new()),
is_worker,
}
}
Expand Down
1 change: 0 additions & 1 deletion cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ mod startup_data;
mod tokio_util;
mod tokio_write;
pub mod version;
pub mod web_worker_behavior;
pub mod workers;

use crate::cli_behavior::CliBehavior;
Expand Down
3 changes: 1 addition & 2 deletions cli/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::resources::Resource;
use crate::tokio_util;
use crate::tokio_write;
use crate::version;
use crate::web_worker_behavior;
use crate::workers;
use deno_core::deno_buf;
use deno_core::Buf;
Expand Down Expand Up @@ -1838,7 +1837,7 @@ fn op_create_worker(

Box::new(futures::future::result(move || -> OpResult {
let parent_state = sc.state().clone();
let behavior = web_worker_behavior::WebWorkerBehavior::new(
let behavior = workers::UserWorkerBehavior::new(
parent_state.flags.clone(),
parent_state.argv.clone(),
);
Expand Down
60 changes: 0 additions & 60 deletions cli/web_worker_behavior.rs

This file was deleted.

59 changes: 59 additions & 0 deletions cli/workers.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,72 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use crate::errors::*;
use crate::flags::DenoFlags;
use crate::isolate::{DenoBehavior, Isolate};
use crate::isolate_state::IsolateState;
use crate::isolate_state::IsolateStateContainer;
use crate::isolate_state::WorkerChannels;
use crate::ops;
use crate::resources;
use crate::startup_data;
use deno_core::deno_buf;
use deno_core::Behavior;
use deno_core::Buf;
use deno_core::JSError;
use deno_core::Op;
use deno_core::StartupData;
use futures::sync::mpsc;
use futures::Future;
use futures::Poll;
use std::sync::Arc;

pub struct UserWorkerBehavior {
pub state: Arc<IsolateState>,
}

impl UserWorkerBehavior {
pub fn new(flags: DenoFlags, argv_rest: Vec<String>) -> Self {
Self {
state: Arc::new(IsolateState::new(flags, argv_rest, None, true)),
}
}
}

impl IsolateStateContainer for UserWorkerBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}

impl IsolateStateContainer for &UserWorkerBehavior {
fn state(&self) -> Arc<IsolateState> {
self.state.clone()
}
}

impl Behavior for UserWorkerBehavior {
fn startup_data(&mut self) -> Option<StartupData> {
Some(startup_data::worker_isolate_init())
}

fn dispatch(
&mut self,
control: &[u8],
zero_copy: deno_buf,
) -> (bool, Box<Op>) {
ops::dispatch_all(self, control, zero_copy, ops::op_selector_worker)
}
}

impl WorkerBehavior for UserWorkerBehavior {
fn set_internal_channels(&mut self, worker_channels: WorkerChannels) {
self.state = Arc::new(IsolateState::new(
self.state.flags.clone(),
self.state.argv.clone(),
Some(worker_channels),
true,
));
}
}

/// Behavior trait specific to workers
pub trait WorkerBehavior: DenoBehavior {
Expand Down