mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-11 19:16:45 +00:00

* chore: generate embeddings * chore: save embedding * chore: vec sqlite * chore: clippy * chore: init vector * chore: create vector db * chore: periodically write embedding * chore: fix compile * chore: skip write * chore: impl search * fix: test * fix: stop scheduler * fix: search * chore: add test * chore: update schema * chore: index all * chore: index * chore: search document content * chore: index document content and title * chore: index all view * chore: rename trait * refactor: remove folder index manager * chore: index folder changes * chore: delete folder search * chore: update logs * chore: update logs * chore: search * chore: add search test * chore: fmt * chore: fix test * chore: fix ios build
78 lines
1.7 KiB
Rust
78 lines
1.7 KiB
Rust
use std::fmt::{Display, Formatter};
|
|
use std::future::Future;
|
|
use std::io;
|
|
|
|
use tokio::runtime;
|
|
use tokio::runtime::Runtime;
|
|
use tokio::task::JoinHandle;
|
|
|
|
pub struct AFPluginRuntime {
|
|
pub inner: Runtime,
|
|
}
|
|
|
|
impl Display for AFPluginRuntime {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
if cfg!(any(target_arch = "wasm32", feature = "local_set")) {
|
|
write!(f, "Runtime(local_set)")
|
|
} else {
|
|
write!(f, "Runtime")
|
|
}
|
|
}
|
|
}
|
|
|
|
impl AFPluginRuntime {
|
|
pub fn new() -> io::Result<Self> {
|
|
let inner = default_tokio_runtime()?;
|
|
Ok(Self { inner })
|
|
}
|
|
|
|
#[track_caller]
|
|
pub fn spawn<F>(&self, future: F) -> JoinHandle<F::Output>
|
|
where
|
|
F: Future + Send + 'static,
|
|
<F as Future>::Output: Send + 'static,
|
|
{
|
|
self.inner.spawn(future)
|
|
}
|
|
|
|
#[track_caller]
|
|
pub fn block_on<F>(&self, f: F) -> F::Output
|
|
where
|
|
F: Future,
|
|
{
|
|
self.inner.block_on(f)
|
|
}
|
|
}
|
|
|
|
#[cfg(feature = "local_set")]
|
|
pub fn default_tokio_runtime() -> io::Result<Runtime> {
|
|
runtime::Builder::new_multi_thread()
|
|
.enable_io()
|
|
.enable_time()
|
|
.thread_name("dispatch-rt-st")
|
|
.build()
|
|
}
|
|
|
|
#[cfg(not(feature = "local_set"))]
|
|
pub fn default_tokio_runtime() -> io::Result<Runtime> {
|
|
runtime::Builder::new_multi_thread()
|
|
.thread_name("dispatch-rt-mt")
|
|
.enable_io()
|
|
.enable_time()
|
|
.on_thread_start(move || {
|
|
tracing::trace!(
|
|
"{:?} thread started: thread_id= {}",
|
|
std::thread::current(),
|
|
thread_id::get()
|
|
);
|
|
})
|
|
.on_thread_stop(move || {
|
|
tracing::trace!(
|
|
"{:?} thread stopping: thread_id= {}",
|
|
std::thread::current(),
|
|
thread_id::get(),
|
|
);
|
|
})
|
|
.build()
|
|
}
|