Skip to content

Commit

Permalink
feat: new fn for controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
frelodev committed Aug 21, 2024
1 parent a99eee1 commit f29ea23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/ffi/js/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl BufferController {
tokio::time::sleep(std::time::Duration::from_millis(200)).await;
match _controller.recv().await {
Ok(event) => {
tsfn.call(event, ThreadsafeFunctionCallMode::NonBlocking); //check this shit with tracing also we could use Ok(event) to get the error
tsfn.call(event, ThreadsafeFunctionCallMode::NonBlocking); //check this with tracing also we could use Ok(event) to get the error
},
Err(crate::Error::Deadlocked) => continue,
Err(e) => break tracing::warn!("error receiving: {}", e),
Expand All @@ -32,6 +32,11 @@ impl BufferController {
Ok(())
}

#[napi(js_name = "try_recv")]
pub async fn js_try_recv(&self) -> napi::Result<Option<TextChange>> {
Ok(self.try_recv().await?)
}

#[napi(js_name = "recv")]
pub async fn js_recv(&self) -> napi::Result<TextChange> {
Ok(self.recv().await?.into())
Expand All @@ -41,4 +46,9 @@ impl BufferController {
pub async fn js_send(&self, op: TextChange) -> napi::Result<()> {
Ok(self.send(op).await?)
}

#[napi(js_name = "content")]
pub async fn js_content(&self) -> napi::Result<String> {
Ok(self.content().await?)
}
}
5 changes: 5 additions & 0 deletions src/ffi/js/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ impl CursorController {
Ok(self.try_recv().await?
.map(|x| JsCursor::from(x)))
}

#[napi(js_name= "recv")]
pub async fn js_recv(&self) -> napi::Result<JsCursor> {
Ok(self.recv().await?.into())
}
}

0 comments on commit f29ea23

Please sign in to comment.