chore: bump to lib 0.5.1

This commit is contained in:
zaaarf 2023-11-30 10:24:01 +01:00
parent 154e8c26b5
commit ca7da92b59
No known key found for this signature in database
GPG key ID: 6445A5CD15E5B40C
3 changed files with 17 additions and 39 deletions

View file

@ -4,12 +4,11 @@ version = "0.1.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.5.0", features = ["global", "sync"] } codemp = { git = "ssh://git@github.com/codewithotherpeopleandchangenamelater/codemp.git", tag = "v0.5.1", features = ["global", "sync"] }
jni = { version = "0.21.1", features = ["invocation"] } jni = { version = "0.21.1", features = ["invocation"] }
jni-sys = "0.3.0" jni-sys = "0.3.0"
log = "0.4.20" log = "0.4.20"
rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"} rifgen = { git = "https://github.com/Kofituo/rifgen.git", rev = "d27d9785b2febcf5527f1deb6a846be5d583f7d7"}
tokio = "1.34.0"
[build-dependencies] [build-dependencies]
flapigen = "0.6.0" flapigen = "0.6.0"

View file

@ -59,18 +59,16 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
StringVec buffers = new StringVec(); //jni moment StringVec buffers = new StringVec(); //jni moment
CodeMP.ACTIVE_BUFFERS.keySet().forEach(buffers::push); CodeMP.ACTIVE_BUFFERS.keySet().forEach(buffers::push);
Optional<String> bufferOptional = CodeMPHandler.selectBuffer(buffers, 100L); Optional<BufferHandler> bufferOptional = CodeMPHandler.selectBuffer(buffers, 100L);
if(bufferOptional.isEmpty()) if(bufferOptional.isEmpty())
continue; continue;
String buffer = bufferOptional.get(); BufferHandler buffer = bufferOptional.get();
BufferHandler handler = CodeMPHandler.getBuffer(buffer);
List<TextChangeWrapper> changeList = new ArrayList<>(); List<TextChangeWrapper> changeList = new ArrayList<>();
while(true) { while(true) {
Optional<TextChangeWrapper> changeOptional; Optional<TextChangeWrapper> changeOptional;
try { try {
changeOptional = handler.tryRecv(); changeOptional = buffer.tryRecv();
} catch(DeadlockedException e) { } catch(DeadlockedException e) {
CodeMP.LOGGER.error(e.getMessage()); CodeMP.LOGGER.error(e.getMessage());
continue; continue;
@ -83,7 +81,7 @@ public class BufferEventAwaiterTask extends Task.Backgroundable implements Dispo
changeList.add(change); changeList.add(change);
} }
Editor bufferEditor = CodeMP.ACTIVE_BUFFERS.get(buffer); Editor bufferEditor = CodeMP.ACTIVE_BUFFERS.get(buffer.getName());
ApplicationManager.getApplication().invokeLaterOnWriteThread(() -> ApplicationManager.getApplication().invokeLaterOnWriteThread(() ->
ApplicationManager.getApplication().runWriteAction(() -> ApplicationManager.getApplication().runWriteAction(() ->
CommandProcessor.getInstance().executeCommand( CommandProcessor.getInstance().executeCommand(

View file

@ -1,6 +1,7 @@
use std::sync::Arc; use std::sync::Arc;
use std::time::Duration; use std::time::Duration;
use codemp::prelude::*; use codemp::prelude::*;
use codemp::tools;
use rifgen::rifgen_attr::{generate_access_methods, generate_interface, generate_interface_doc}; use rifgen::rifgen_attr::{generate_access_methods, generate_interface, generate_interface_doc};
pub mod glue { //rifgen generated code pub mod glue { //rifgen generated code
@ -67,7 +68,7 @@ impl CodeMPHandler {
} }
#[generate_interface] #[generate_interface]
fn select_buffer(mut buffer_ids: StringVec, timeout: i64) -> CodempResult<Option<String>> { fn select_buffer(mut buffer_ids: StringVec, timeout: i64) -> CodempResult<Option<BufferHandler>> {
let mut buffers = Vec::new(); let mut buffers = Vec::new();
for id in buffer_ids.v.iter_mut() { for id in buffer_ids.v.iter_mut() {
match CODEMP_INSTANCE.get_buffer(id.as_str()) { match CODEMP_INSTANCE.get_buffer(id.as_str()) {
@ -76,35 +77,15 @@ impl CodeMPHandler {
} }
} }
let (tx, mut rx) = tokio::sync::mpsc::unbounded_channel(); let result = CODEMP_INSTANCE.rt().block_on(tools::select_buffer(
let mut tasks = Vec::new(); buffers.as_slice(),
for buffer in buffers { Some(Duration::from_millis(timeout as u64))
let _tx = tx.clone(); ));
let _buffer = buffer.clone();
tasks.push(CODEMP_INSTANCE.rt().spawn(async move { match result {
match _buffer.poll().await { Err(e) => Err(e),
Ok(()) => _tx.send(Ok(Some(_buffer.name.clone()))), Ok(buffer) =>
Err(_) => _tx.send(Err(CodempError::Channel { send: true })), Ok(buffer.map(|buffer| BufferHandler { buffer }))
}
}))
}
let _tx = tx.clone();
tasks.push(CODEMP_INSTANCE.rt().spawn(async move {
tokio::time::sleep(Duration::from_millis(timeout as u64)).await;
_tx.send(Ok(None))
}));
loop {
match CODEMP_INSTANCE.rt().block_on(rx.recv()) {
None => return Err(CodempError::Channel { send: false }),
Some(Err(_)) => continue,
Some(Ok(None)) => return Ok(None),
Some(Ok(Some(x))) => {
for t in tasks {
t.abort();
}
return Ok(Some(x.clone()));
},
}
} }
} }
} }
@ -180,7 +161,7 @@ impl BufferHandler {
#[generate_interface] #[generate_interface]
fn get_name(&self) -> String { fn get_name(&self) -> String {
self.buffer.name.clone() self.buffer.name().to_string()
} }
#[generate_interface] #[generate_interface]