Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions impit-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use impit::{
impit::{Impit, ImpitBuilder},
request::RequestOptions,
};
use napi::Env;
use napi::{bindgen_prelude::ObjectFinalize, Env};
use napi_derive::napi;

mod abortable_stream;
Expand Down Expand Up @@ -37,11 +37,18 @@ use request::{HttpMethod, RequestInit};
///
/// Note that all the requests made by this instance will share the same configuration,
/// resources (e.g. cookie jar and connection pool), and other settings.
#[napi(js_name = "Impit")]
#[napi(js_name = "Impit", custom_finalize)]
pub struct ImpitWrapper {
inner: Impit<cookies::NodeCookieJar>,
}

impl ObjectFinalize for ImpitWrapper {
fn finalize(self, env: Env) -> napi::Result<()> {
env.adjust_external_memory(-500 * 1024)?;
Ok(())
}
}

#[napi]
impl ImpitWrapper {
/// Creates a new `Impit` instance with the given options.
Expand All @@ -66,6 +73,8 @@ impl ImpitWrapper {
let config: Result<ImpitBuilder<cookies::NodeCookieJar>, napi::Error> =
options.unwrap_or_default().into_builder(env);

let _ = env.adjust_external_memory(500 * 1024);

// `quinn` for h3 requires existing async runtime.
// This runs the `config.build` function in the napi-managed tokio runtime which remains available
// throughout the lifetime of the `ImpitWrapper` instance.
Expand Down