mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: Stream chat message (#5498)
* chore: stream message * chore: stream message * chore: fix streaming * chore: fix clippy
This commit is contained in:
@ -8,7 +8,7 @@ edition = "2018"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
chrono = { workspace = true, default-features = false, features = ["clock"] }
|
||||
bytes = { version = "1.5" }
|
||||
pin-project = "1.1.3"
|
||||
futures-core = { version = "0.3" }
|
||||
@ -21,6 +21,8 @@ tempfile = "3.8.1"
|
||||
validator = "0.16.0"
|
||||
tracing.workspace = true
|
||||
atomic_refcell = "0.1"
|
||||
allo-isolate = { version = "^0.1", features = ["catch-unwind"], optional = true }
|
||||
futures = "0.3.30"
|
||||
|
||||
[dev-dependencies]
|
||||
rand = "0.8.5"
|
||||
@ -28,7 +30,8 @@ futures = "0.3.30"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
zip = { version = "0.6.6", features = ["deflate"] }
|
||||
brotli = { version = "3.4.0", optional = true }
|
||||
brotli = { version = "3.4.0", optional = true }
|
||||
|
||||
[features]
|
||||
compression = ["brotli"]
|
||||
compression = ["brotli"]
|
||||
isolate_flutter = ["allo-isolate"]
|
||||
|
44
frontend/rust-lib/lib-infra/src/isolate_stream.rs
Normal file
44
frontend/rust-lib/lib-infra/src/isolate_stream.rs
Normal file
@ -0,0 +1,44 @@
|
||||
use allo_isolate::{IntoDart, Isolate};
|
||||
use futures::Sink;
|
||||
use pin_project::pin_project;
|
||||
use std::pin::Pin;
|
||||
use std::task::{Context, Poll};
|
||||
|
||||
#[pin_project]
|
||||
pub struct IsolateSink {
|
||||
isolate: Isolate,
|
||||
}
|
||||
|
||||
impl IsolateSink {
|
||||
pub fn new(isolate: Isolate) -> Self {
|
||||
Self { isolate }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Sink<T> for IsolateSink
|
||||
where
|
||||
T: IntoDart,
|
||||
{
|
||||
type Error = ();
|
||||
|
||||
fn poll_ready(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn start_send(self: Pin<&mut Self>, item: T) -> Result<(), Self::Error> {
|
||||
let this = self.project();
|
||||
if this.isolate.post(item) {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
fn poll_flush(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
|
||||
fn poll_close(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
}
|
@ -19,6 +19,8 @@ if_wasm! {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "isolate_flutter")]
|
||||
pub mod isolate_stream;
|
||||
pub mod priority_task;
|
||||
pub mod ref_map;
|
||||
pub mod util;
|
||||
|
Reference in New Issue
Block a user