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,6 +1,6 @@
{ {
"name": "@drop/droplet", "name": "@drop/droplet",
"version": "0.4.1", "version": "0.4.2",
"main": "index.js", "main": "index.js",
"types": "index.d.ts", "types": "index.d.ts",
"napi": { "napi": {

View File

@ -1,14 +1,17 @@
use std::{ use std::{
fs::File, fs::File,
io::{BufRead, BufReader}, io::{BufRead, BufReader},
path::Path, path::Path, thread,
}; };
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
use gxhash::gxhash128; use gxhash::gxhash128;
use napi::{Error, JsFunction, JsNumber}; use napi::{
threadsafe_function::{ErrorStrategy, ThreadsafeFunction, ThreadsafeFunctionCallMode},
Error, JsFunction,
};
use serde::Serialize; use serde::Serialize;
use serde_json::json; use serde_json::json;
use uuid::Uuid; use uuid::Uuid;
@ -26,6 +29,19 @@ struct Chunk {
checksum: String, 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] #[napi]
pub fn generate_manifest( pub fn generate_manifest(
dir: String, dir: String,