diff --git a/package.json b/package.json index 25f94e3..9f0ab72 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@drop/droplet", - "version": "0.4.1", + "version": "0.4.2", "main": "index.js", "types": "index.d.ts", "napi": { diff --git a/src/manifest.rs b/src/manifest.rs index 261362a..cd711a8 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -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 = 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,