Skip to content

Commit 379e7ad

Browse files
authored
feat(bridge): add option to configure thread pool size for async calls (#113)
* feat(bridge): add option to configure thread pool size for async calls * fix(deps): make anyhow not an optional dependency
1 parent c610868 commit 379e7ad

File tree

10 files changed

+830
-572
lines changed

10 files changed

+830
-572
lines changed

Cargo.lock

Lines changed: 117 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ await str.length(); // 11
262262
await str.toString(); // 'Hello World'
263263
```
264264

265+
### Setting the number of threads
266+
267+
When using asynchronous functions, by default, the number of threads used by these functions
268+
is determined by the number of physical CPUs available.
269+
In order to change this behaviour, set the `JAVA_BRIDGE_THREAD_POOL_SIZE` environment variable
270+
to the desired amount of threads.
271+
272+
Note: Setting this to a non-numeric value will cause an error to be thrown during startup.
273+
265274
### Implement a Java interface
266275

267276
You can also implement a Java interface in node.js using the

crates/java-bridge/Cargo.toml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
22
edition = "2021"
33
name = "java"
4-
version = "2.4.0"
4+
version = "2.8.0"
55

66
[lib]
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
napi = { version = "2.16.0", default-features = false, features = [
10+
napi = { version = "2.16.17", default-features = false, features = [
1111
"napi2",
1212
"napi3",
1313
"napi4",
@@ -18,26 +18,26 @@ napi = { version = "2.16.0", default-features = false, features = [
1818
] }
1919
napi-derive = "2.16.13"
2020
futures = "0.3.31"
21-
java-locator = "0.1.8"
21+
java-locator = "0.1.9"
2222
lazy_static = "1.5.0"
23-
rand = "0.8.5"
23+
rand = "0.9.0"
2424
glob = "0.3.1"
2525
java-rs = { path = "../java-rs" }
2626
app-state = { git = "https://github.com/MarkusJx/app-state" }
2727
# TODO: remove this once the next version of napi-sys is released
2828
libloading = "0.8.6"
29-
anyhow = { version = "1.0.94", optional = true }
30-
log = { version = "0.4.22", optional = true }
29+
anyhow = "1.0.97"
30+
log = { version = "0.4.27", optional = true }
3131
log4rs = { version = "1.3.0", features = ["json_format"], optional = true }
32-
serde = { version = "1.0.216", optional = true }
32+
serde = { version = "1.0.219", optional = true }
3333
smart-default = "0.7.1"
34-
spin_sleep = "1.3.0"
34+
spin_sleep = "1.3.1"
3535

3636
[build-dependencies]
37-
napi-build = "2.1.4"
37+
napi-build = "2.1.6"
3838

3939
[features]
4040
default = []
4141
all = ["log", "type_check"]
4242
type_check = ["java-rs/type_check"]
43-
log = ["dep:log", "dep:log4rs", "dep:serde", "dep:anyhow", "java-rs/log"]
43+
log = ["dep:log", "dep:log4rs", "dep:serde", "java-rs/log"]

crates/java-bridge/src/logging/log.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,8 @@ mod logging {
149149
/// Call {@link logging.setLogCallbacks} to enable the `node` appender again.
150150
pub fn reset_log_callbacks() -> napi::Result<()> {
151151
debug!("Resetting log callbacks");
152-
Ok(NodeWriter::set_callbacks(None, None))
152+
NodeWriter::set_callbacks(None, None);
153+
Ok(())
153154
}
154155

155156
#[napi]

0 commit comments

Comments
 (0)