async utils that might fix my problem

This commit is contained in:
DecDuck
2024-10-11 15:51:32 +11:00
parent 174e48667f
commit f88fd2a016
2 changed files with 19 additions and 3 deletions

View File

@ -1,14 +1,17 @@
use std::{
fs::File,
io::{BufRead, BufReader},
path::Path,
path::Path, thread,
};
#[cfg(unix)]
use std::os::unix::fs::PermissionsExt;
use gxhash::gxhash128;
use napi::{Error, JsFunction, JsNumber};
use napi::{
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
Error, JsFunction,
};
use serde::Serialize;
use serde_json::json;
use uuid::Uuid;
@ -26,6 +29,19 @@ struct Chunk {
checksum: String,
}
#[napi]
pub fn call_alt_thread_func(callback: JsFunction) -> Result<(), Error> {
let tsfn: ThreadsafeFunction<u32, ErrorStrategy::CalleeHandled> = callback
.create_threadsafe_function(0, |ctx| {
ctx.env.create_uint32(ctx.value + 1).map(|v| vec![v])
})?;
let tsfn = tsfn.clone();
thread::spawn(move || {
tsfn.call(Ok(0), ThreadsafeFunctionCallMode::Blocking);
});
Ok(())
}
#[napi]
pub fn generate_manifest(
dir: String,