Sha256: 00d48122fa2ccbf1fe0b110ce3cf22590eda54b3ddec0134b1f9376eb1169645

Contents?: true

Size: 1.07 KB

Versions: 39

Compression:

Stored size: 1.07 KB

Contents

#![allow(dead_code)]

use std::pin::Pin;
use std::task::{Context, Poll};
use tokio::sync::mpsc::{self, Receiver, Sender, UnboundedReceiver, UnboundedSender};
use tokio_stream::Stream;

struct UnboundedStream<T> {
    recv: UnboundedReceiver<T>,
}
impl<T> Stream for UnboundedStream<T> {
    type Item = T;
    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
        Pin::into_inner(self).recv.poll_recv(cx)
    }
}

pub fn unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>) {
    let (tx, rx) = mpsc::unbounded_channel();

    let stream = UnboundedStream { recv: rx };

    (tx, stream)
}

struct BoundedStream<T> {
    recv: Receiver<T>,
}
impl<T> Stream for BoundedStream<T> {
    type Item = T;
    fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<T>> {
        Pin::into_inner(self).recv.poll_recv(cx)
    }
}

pub fn channel_stream<T: Unpin>(size: usize) -> (Sender<T>, impl Stream<Item = T>) {
    let (tx, rx) = mpsc::channel(size);

    let stream = BoundedStream { recv: rx };

    (tx, stream)
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/tokio-1.43.0/tests/support/mpsc_stream.rs
wasmtime-29.0.0 ./ext/cargo-vendor/tokio-1.43.0/tests/support/mpsc_stream.rs
wasmtime-28.0.0 ./ext/cargo-vendor/tokio-1.43.0/tests/support/mpsc_stream.rs
wasmtime-27.0.0 ./ext/cargo-vendor/tokio-1.41.1/tests/support/mpsc_stream.rs
wasmtime-26.0.0 ./ext/cargo-vendor/tokio-1.41.0/tests/support/mpsc_stream.rs
wasmtime-25.0.2 ./ext/cargo-vendor/tokio-1.40.0/tests/support/mpsc_stream.rs
wasmtime-25.0.1 ./ext/cargo-vendor/tokio-1.39.3/tests/support/mpsc_stream.rs
wasmtime-25.0.0 ./ext/cargo-vendor/tokio-1.39.3/tests/support/mpsc_stream.rs
wasmtime-24.0.0 ./ext/cargo-vendor/tokio-1.39.3/tests/support/mpsc_stream.rs
wasmtime-23.0.2 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-22.0.0 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-21.0.1 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-20.0.2 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-20.0.0 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-18.0.3 ./ext/cargo-vendor/tokio-1.36.0/tests/support/mpsc_stream.rs
wasmtime-17.0.1 ./ext/cargo-vendor/tokio-1.35.1/tests/support/mpsc_stream.rs
wasmtime-17.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/support/mpsc_stream.rs
wasmtime-16.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/support/mpsc_stream.rs
wasmtime-15.0.1 ./ext/cargo-vendor/tokio-1.35.1/tests/support/mpsc_stream.rs
wasmtime-15.0.0 ./ext/cargo-vendor/tokio-1.35.1/tests/support/mpsc_stream.rs