@@ -22,8 +22,7 @@ static WORKER_TERMINATOR: OnceCell<
2222 ThreadsafeFunction < NapiWorkerTermination , ErrorStrategy :: Fatal > ,
2323> = OnceCell :: new ( ) ;
2424
25- static PENDING_CREATIONS : OnceCell < Mutex < VecDeque < ( Arc < WorkerOptions > , oneshot:: Sender < u32 > ) > > > =
26- OnceCell :: new ( ) ;
25+ static PENDING_CREATIONS : OnceCell < Mutex < VecDeque < oneshot:: Sender < u32 > > > > = OnceCell :: new ( ) ;
2726
2827#[ napi]
2928#[ allow( unused) ]
@@ -58,6 +57,8 @@ pub fn register_worker_scheduler(
5857pub async fn create_worker ( options : Arc < WorkerOptions > ) -> anyhow:: Result < u32 > {
5958 let ( tx, rx) = oneshot:: channel ( ) ;
6059
60+ let napi_options = ( & options) . into ( ) ;
61+
6162 {
6263 let pending = PENDING_CREATIONS . get_or_init ( || Mutex :: new ( VecDeque :: new ( ) ) ) ;
6364 // ensure pool entry exists for these options so scale ops can observe it
@@ -66,13 +67,13 @@ pub async fn create_worker(options: Arc<WorkerOptions>) -> anyhow::Result<u32> {
6667 . lock ( )
6768 . entry ( options. clone ( ) )
6869 . or_default ( ) ;
69- pending. lock ( ) . push_back ( ( options . clone ( ) , tx ) ) ;
70+ pending. lock ( ) . push_back ( tx ) ;
7071 }
7172
7273 if let Some ( creator) = WORKER_CREATOR . get ( ) {
7374 creator. call (
7475 NapiWorkerCreation {
75- options : options . into ( ) ,
76+ options : napi_options ,
7677 } ,
7778 ThreadsafeFunctionCallMode :: NonBlocking ,
7879 ) ;
@@ -87,19 +88,10 @@ pub async fn create_worker(options: Arc<WorkerOptions>) -> anyhow::Result<u32> {
8788#[ napi]
8889#[ allow( unused) ]
8990pub fn worker_created ( worker_id : u32 ) {
90- if let Some ( pending) = PENDING_CREATIONS . get ( ) {
91- if let Some ( ( options, tx) ) = pending. lock ( ) . pop_front ( ) {
92- // record into global pool
93- WORKER_POOL_OPERATION
94- . pools
95- . lock ( )
96- . entry ( options. clone ( ) )
97- . or_default ( )
98- . idle_workers
99- . lock ( )
100- . push ( worker_id) ;
101- let _ = tx. send ( worker_id) ;
102- }
91+ if let Some ( pending) = PENDING_CREATIONS . get ( )
92+ && let Some ( tx) = pending. lock ( ) . pop_front ( )
93+ {
94+ let _ = tx. send ( worker_id) ;
10395 }
10496}
10597
0 commit comments