feat: faster accessor, fix prelude

This commit is contained in:
əlemi 2023-08-19 05:04:25 +02:00
parent 4f3e09abd3
commit 4562c2732b
2 changed files with 8 additions and 6 deletions

View file

@ -38,21 +38,23 @@ impl Instance {
} }
} }
pub fn rt(&self) -> &Runtime { &self.runtime }
pub fn connect(&self, addr: &str) -> Result<(), Error> { pub fn connect(&self, addr: &str) -> Result<(), Error> {
*self.client.lock().expect("client mutex poisoned") = Some(self.runtime.block_on(Client::new(addr))?); *self.client.lock().expect("client mutex poisoned") = Some(self.rt().block_on(Client::new(addr))?);
Ok(()) Ok(())
} }
pub fn join(&self, session: &str) -> Result<Arc<CursorController>, Error> { pub fn join(&self, session: &str) -> Result<Arc<CursorController>, Error> {
self.if_client(|c| self.runtime.block_on(c.join(session)))? self.if_client(|c| self.rt().block_on(c.join(session)))?
} }
pub fn create(&self, path: &str, content: Option<&str>) -> Result<(), Error> { pub fn create(&self, path: &str, content: Option<&str>) -> Result<(), Error> {
self.if_client(|c| self.runtime.block_on(c.create(path, content)))? self.if_client(|c| self.rt().block_on(c.create(path, content)))?
} }
pub fn attach(&self, path: &str) -> Result<Arc<BufferController>, Error> { pub fn attach(&self, path: &str) -> Result<Arc<BufferController>, Error> {
self.if_client(|c| self.runtime.block_on(c.attach(path)))? self.if_client(|c| self.rt().block_on(c.attach(path)))?
} }
pub fn get_cursor(&self) -> Result<Arc<CursorController>, Error> { pub fn get_cursor(&self) -> Result<Arc<CursorController>, Error> {

View file

@ -7,5 +7,5 @@ pub use crate::buffer::controller::BufferController as CodempBufferController;
pub use crate::buffer::TextChange as CodempTextChange; pub use crate::buffer::TextChange as CodempTextChange;
pub use crate::proto::CursorPosition as CodempCursorPosition; pub use crate::proto::CursorPosition as CodempCursorPosition;
#[cfg(feature = "static")] #[cfg(feature = "global")]
pub use crate::instance::INSTANCE as CODEMP_INSTANCE; pub use crate::instance::global::INSTANCE as CODEMP_INSTANCE;