[][src]Function smol::iter

pub fn iter<T: Send + 'static>(
    iter: impl Iterator<Item = T> + Send + 'static
) -> impl Stream<Item = T> + Send + Unpin + 'static

Creates a stream that iterates on a thread.

This adapter converts any kind of synchronous iterator into an asynchronous stream by running it on the blocking executor and sending items back over a channel.

Examples

List files in the current directory:

use futures::stream::StreamExt;
use smol::{blocking, iter};
use std::fs;

// Load a directory.
let mut dir = blocking!(fs::read_dir("."))?;
let mut dir = iter(dir);

// Iterate over the contents of the directory.
while let Some(res) = dir.next().await {
    println!("{}", res?.file_name().to_string_lossy());
}