napi_h/
async_cleanup_hook.rs

1use std::mem;
2
3use crate::{sys, Status};
4
5/// Notice
6/// The hook will be removed if `AsyncCleanupHook` was `dropped`.
7/// If you want keep the hook until node process exited, call the `AsyncCleanupHook::forget`.
8#[repr(transparent)]
9pub struct AsyncCleanupHook(pub(crate) sys::napi_async_cleanup_hook_handle);
10
11impl AsyncCleanupHook {
12  /// Safe to forget it.
13  /// Things will be cleanup before process exited.
14  pub fn forget(self) {
15    mem::forget(self);
16  }
17}
18
19impl Drop for AsyncCleanupHook {
20  fn drop(&mut self) {
21    let status = unsafe { sys::napi_remove_async_cleanup_hook(self.0) };
22    assert!(
23      status == sys::Status::napi_ok,
24      "Delete async cleanup hook failed: {}",
25      Status::from(status)
26    );
27  }
28}