summaryrefslogtreecommitdiff
path: root/cli/resources.rs
diff options
context:
space:
mode:
authorandy finch <andyfinch7@gmail.com>2019-04-04 05:33:32 -0400
committerRyan Dahl <ry@tinyclouds.org>2019-04-04 05:33:32 -0400
commit0e7311e1717edd312d371148f331fb558d9bcc4b (patch)
tree38957fde88f8359886f4f7a00bea91668c7609b3 /cli/resources.rs
parent8c8576619852ee8b8095ca735f6d517a7e707e79 (diff)
Non-fatal compile_sync failures (#2039)
And model worker resources as Stream
Diffstat (limited to 'cli/resources.rs')
-rw-r--r--cli/resources.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/resources.rs b/cli/resources.rs
index 817f6062d..701d5a937 100644
--- a/cli/resources.rs
+++ b/cli/resources.rs
@@ -346,6 +346,31 @@ pub fn get_message_from_worker(rid: ResourceId) -> WorkerReceiver {
WorkerReceiver { rid }
}
+pub struct WorkerReceiverStream {
+ rid: ResourceId,
+}
+
+// Invert the dumbness that tokio_process causes by making Child itself a future.
+impl Stream for WorkerReceiverStream {
+ type Item = Buf;
+ type Error = DenoError;
+
+ fn poll(&mut self) -> Poll<Option<Buf>, DenoError> {
+ 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())
+ }),
+ _ => Err(bad_resource()),
+ }
+ }
+}
+
+pub fn get_message_stream_from_worker(rid: ResourceId) -> WorkerReceiverStream {
+ WorkerReceiverStream { rid }
+}
+
#[cfg_attr(feature = "cargo-clippy", allow(stutter))]
pub struct ChildResources {
pub child_rid: ResourceId,