Nucli refactor crate stream (#2828)

* nu-stream is building on its own, now clean up Cargo.toml

* replace the stream crate in nu-cli

* cc

* since we moved stream out of the nu-cli crate and into its own crate we need to remove pub(crate) and just make it pub

* clean up the prelude and hand merge everything together

* clean up Cargo.tom

* cargo fmt along with Cargo.lock
This commit is contained in:
Michael Angerman
2020-12-27 21:34:27 -08:00
committed by GitHub
parent 98537ce8b7
commit 5ff4bcfb7a
15 changed files with 136 additions and 12 deletions

View File

@ -0,0 +1,35 @@
use crate::prelude::*;
use futures::task::Poll;
use std::sync::atomic::{AtomicBool, Ordering};
pub struct InterruptibleStream<V> {
inner: BoxStream<'static, V>,
interrupt_signal: Arc<AtomicBool>,
}
impl<V> InterruptibleStream<V> {
pub fn new<S>(inner: S, interrupt_signal: Arc<AtomicBool>) -> InterruptibleStream<V>
where
S: Stream<Item = V> + Send + 'static,
{
InterruptibleStream {
inner: inner.boxed(),
interrupt_signal,
}
}
}
impl<V> Stream for InterruptibleStream<V> {
type Item = V;
fn poll_next(
mut self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> core::task::Poll<Option<Self::Item>> {
if self.interrupt_signal.load(Ordering::SeqCst) {
Poll::Ready(None)
} else {
Stream::poll_next(std::pin::Pin::new(&mut self.inner), cx)
}
}
}