Merge Worker and Isolate types (#2078)

Reduces generics.
This commit is contained in:
Ryan Dahl 2019-04-08 17:10:00 -04:00 committed by GitHub
parent 734cf781c6
commit 2debbdacb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 359 additions and 631 deletions

View file

@ -35,6 +35,7 @@ use std::sync::{Arc, Mutex};
use tokio;
use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpStream;
use tokio::sync::mpsc;
use tokio_process;
pub type ResourceId = u32; // Sometimes referred to RID.
@ -309,7 +310,7 @@ pub fn add_worker(wc: WorkerChannels) -> Resource {
pub fn post_message_to_worker(
rid: ResourceId,
buf: Buf,
) -> futures::sink::Send<futures::sync::mpsc::Sender<Buf>> {
) -> futures::sink::Send<mpsc::Sender<Buf>> {
let mut table = RESOURCE_TABLE.lock().unwrap();
let maybe_repr = table.get_mut(&rid);
match maybe_repr {
@ -334,9 +335,10 @@ impl Future for WorkerReceiver {
let mut table = RESOURCE_TABLE.lock().unwrap();
let maybe_repr = table.get_mut(&self.rid);
match maybe_repr {
Some(Repr::Worker(ref mut wc)) => wc.1.poll().map_err(|()| {
errors::new(errors::ErrorKind::Other, "recv msg error".to_string())
}),
Some(Repr::Worker(ref mut wc)) => wc
.1
.poll()
.map_err(|err| errors::new(errors::ErrorKind::Other, err.to_string())),
_ => Err(bad_resource()),
}
}
@ -359,9 +361,10 @@ impl Stream for WorkerReceiverStream {
let mut table = RESOURCE_TABLE.lock().unwrap();
let maybe_repr = table.get_mut(&self.rid);
match maybe_repr {
Some(Repr::Worker(ref mut wc)) => wc.1.poll().map_err(|()| {
errors::new(errors::ErrorKind::Other, "recv msg error".to_string())
}),
Some(Repr::Worker(ref mut wc)) => wc
.1
.poll()
.map_err(|err| errors::new(errors::ErrorKind::Other, err.to_string())),
_ => Err(bad_resource()),
}
}