(&self, event: &RustHookEvent)
| 5482 | |
| 5483 | impl RustHookHandler for NodeCallbackHandler { |
| 5484 | fn handle(&self, event: &RustHookEvent) -> RustHookResponse { |
| 5485 | let Ok(event_json) = serde_json::to_value(event) else { |
| 5486 | return RustHookResponse::continue_(); |
| 5487 | }; |
| 5488 | |
| 5489 | let (tx, rx) = std::sync::mpsc::sync_channel::<RustHookResponse>(1); |
| 5490 | |
| 5491 | self.tsfn.call_with_return_value( |
| 5492 | Ok(event_json), |
| 5493 | napi::threadsafe_function::ThreadsafeFunctionCallMode::NonBlocking, |
| 5494 | move |ret: napi::JsUnknown| { |
| 5495 | let response = |
| 5496 | parse_js_hook_response(ret).unwrap_or_else(|_| RustHookResponse::continue_()); |
| 5497 | let _ = tx.send(response); |
| 5498 | Ok(()) |
| 5499 | }, |
| 5500 | ); |
| 5501 | |
| 5502 | // block_in_place: signal to tokio that this thread will block; |
| 5503 | // valid only on multi-thread runtime (which get_runtime() always creates). |
| 5504 | tokio::task::block_in_place(|| { |
| 5505 | rx.recv_timeout(std::time::Duration::from_millis(self.timeout_ms)) |
| 5506 | .unwrap_or_else(|_| RustHookResponse::continue_()) |
| 5507 | }) |
| 5508 | } |
| 5509 | } |
| 5510 | |
| 5511 | /// Parse the return value from a JS hook callback into a `HookResponse`. |
nothing calls this directly
no test coverage detected