mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
refactor: Make stream utils generic over the error type
This commit is contained in:
@@ -209,7 +209,7 @@ pub(super) async fn compact(
|
|||||||
let parallelism = parallelism.unwrap_or(1);
|
let parallelism = parallelism.unwrap_or(1);
|
||||||
let results = maps
|
let results = maps
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_stream()
|
.try_stream::<conduwuit::Error>()
|
||||||
.paralleln_and_then(runtime, parallelism, move |map| {
|
.paralleln_and_then(runtime, parallelism, move |map| {
|
||||||
map.compact_blocking(options.clone())?;
|
map.compact_blocking(options.clone())?;
|
||||||
Ok(map.name().to_owned())
|
Ok(map.name().to_owned())
|
||||||
|
|||||||
@@ -3,19 +3,17 @@ use futures::{
|
|||||||
stream::{Stream, TryStream},
|
stream::{Stream, TryStream},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{Error, Result};
|
|
||||||
|
|
||||||
pub trait IterStream<I: IntoIterator + Send> {
|
pub trait IterStream<I: IntoIterator + Send> {
|
||||||
/// Convert an Iterator into a Stream
|
/// Convert an Iterator into a Stream
|
||||||
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send;
|
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send;
|
||||||
|
|
||||||
/// Convert an Iterator into a TryStream
|
/// Convert an Iterator into a TryStream with a generic error type
|
||||||
fn try_stream(
|
fn try_stream<E>(
|
||||||
self,
|
self,
|
||||||
) -> impl TryStream<
|
) -> impl TryStream<
|
||||||
Ok = <I as IntoIterator>::Item,
|
Ok = <I as IntoIterator>::Item,
|
||||||
Error = Error,
|
Error = E,
|
||||||
Item = Result<<I as IntoIterator>::Item, Error>,
|
Item = Result<<I as IntoIterator>::Item, E>,
|
||||||
> + Send;
|
> + Send;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,12 +26,12 @@ where
|
|||||||
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send { stream::iter(self) }
|
fn stream(self) -> impl Stream<Item = <I as IntoIterator>::Item> + Send { stream::iter(self) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn try_stream(
|
fn try_stream<E>(
|
||||||
self,
|
self,
|
||||||
) -> impl TryStream<
|
) -> impl TryStream<
|
||||||
Ok = <I as IntoIterator>::Item,
|
Ok = <I as IntoIterator>::Item,
|
||||||
Error = Error,
|
Error = E,
|
||||||
Item = Result<<I as IntoIterator>::Item, Error>,
|
Item = Result<<I as IntoIterator>::Item, E>,
|
||||||
> + Send {
|
> + Send {
|
||||||
self.stream().map(Ok)
|
self.stream().map(Ok)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
//! Synchronous combinator extensions to futures::TryStream
|
//! Synchronous combinator extensions to futures::TryStream
|
||||||
|
|
||||||
|
use std::result::Result;
|
||||||
|
|
||||||
use futures::{TryFuture, TryStream, TryStreamExt};
|
use futures::{TryFuture, TryStream, TryStreamExt};
|
||||||
|
|
||||||
use super::automatic_width;
|
use super::automatic_width;
|
||||||
use crate::Result;
|
|
||||||
|
|
||||||
/// Concurrency extensions to augment futures::TryStreamExt. broad_ combinators
|
/// Concurrency extensions to augment futures::TryStreamExt. broad_ combinators
|
||||||
/// produce out-of-order
|
/// produce out-of-order
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ async fn get_auth_chain_outer(
|
|||||||
|
|
||||||
let chunk_cache: Vec<_> = chunk
|
let chunk_cache: Vec<_> = chunk
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.try_stream()
|
.try_stream::<conduwuit::Error>()
|
||||||
.broad_and_then(|(shortid, event_id)| async move {
|
.broad_and_then(|(shortid, event_id)| async move {
|
||||||
if let Ok(cached) = self.get_cached_eventid_authchain(&[shortid]).await {
|
if let Ok(cached) = self.get_cached_eventid_authchain(&[shortid]).await {
|
||||||
return Ok(cached.to_vec());
|
return Ok(cached.to_vec());
|
||||||
|
|||||||
Reference in New Issue
Block a user