use nodejs::neon::context::TaskContext;
use nodejs::neon::result::NeonResult;
pub fn sync_node<T: Send + 'static>(
f: impl FnOnce(TaskContext) -> NeonResult<T> + Send + 'static,
) -> Option<T> {
let nodejs_channel = nodejs::channel();
let (tx, rx) = std::sync::mpsc::sync_channel::<T>(0);
nodejs_channel.send(move |cx| {
let val = f(cx)?;
tx.send(val).unwrap();
Ok(())
});
rx.recv().ok()
}