Skip to content

Commit c7cdde4

Browse files
committed
move to scoped pools
1 parent 22a7e3d commit c7cdde4

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

native/html5ever_nif/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ rustler_codegen = { git = "https://github.com/hansihe/Rustler" }
1818
html5ever = "*"
1919
tendril = "*"
2020
lazy_static = "*"
21+
scoped-pool = "*"

native/html5ever_nif/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ extern crate rustler;
44
extern crate lazy_static;
55
extern crate html5ever;
66
extern crate tendril;
7+
extern crate scoped_pool;
78

89
use std::borrow::Cow;
910
use std::fmt;
@@ -89,7 +90,7 @@ fn parse_async<'a>(env: NifEnv<'a>, args: &Vec<NifTerm<'a>>) -> NifResult<NifTer
8990

9091
let pid = env.pid();
9192

92-
thread::spawn(move || {
93+
POOL.spawn(move || {
9394
owned_env.send(pid, |inner_env| {
9495
match panic::catch_unwind(|| {
9596
let input_term = input_term_saved.load(inner_env);
@@ -135,6 +136,10 @@ rustler_export_nifs!(
135136
Some(on_load)
136137
);
137138

139+
lazy_static! {
140+
static ref POOL: scoped_pool::Pool = scoped_pool::Pool::new(4);
141+
}
142+
138143
fn on_load<'a>(env: NifEnv<'a>, _load_info: NifTerm<'a>) -> bool {
139144
true
140145
}

0 commit comments

Comments
 (0)