@@ -319,14 +319,14 @@ impl JsInstance {
319319
320320 async fn send_request < T > (
321321 & self ,
322- request : impl FnOnce ( oneshot :: Sender < WorkerReply < T > > ) -> JsWorkerRequest ,
322+ request : impl FnOnce ( JsReplyTx < T > ) -> JsWorkerRequest ,
323323 ) -> Result < T , WorkerDisconnected > {
324324 let ( reply_tx, reply_rx) = oneshot:: channel ( ) ;
325325 self . request_tx
326326 . send_async ( request ( reply_tx) )
327327 . await
328328 . map_err ( |_| WorkerDisconnected ) ?;
329- let WorkerReply { value, trapped } = reply_rx. await . map_err ( |_| WorkerDisconnected ) ?;
329+ let JsWorkerReply { value, trapped } = reply_rx. await . map_err ( |_| WorkerDisconnected ) ?;
330330 if trapped {
331331 self . trapped . store ( true , Ordering :: Relaxed ) ;
332332 }
@@ -456,60 +456,67 @@ impl JsInstance {
456456#[ derive( Clone , Copy , Debug ) ]
457457struct WorkerDisconnected ;
458458
459- struct WorkerReply < T > {
459+ struct JsWorkerReply < T > {
460460 value : T ,
461461 trapped : bool ,
462462}
463463
464+ type JsReplyTx < T > = oneshot:: Sender < JsWorkerReply < T > > ;
465+
466+ /// Requests sent to the dedicated JS worker thread.
467+ ///
468+ /// Most variants carry a `reply_tx` because the worker thread owns the isolate,
469+ /// executes the request there, and then has to send both the typed result and
470+ /// the worker's trapped-bit back to the async caller.
464471enum JsWorkerRequest {
465472 RunFunction ( Box < dyn FnOnce ( ) -> LocalBoxFuture < ' static , ( ) > + Send > ) ,
466473 UpdateDatabase {
467- reply_tx : oneshot :: Sender < WorkerReply < anyhow:: Result < UpdateDatabaseResult > > > ,
474+ reply_tx : JsReplyTx < anyhow:: Result < UpdateDatabaseResult > > ,
468475 program : Program ,
469476 old_module_info : Arc < ModuleInfo > ,
470477 policy : MigrationPolicy ,
471478 } ,
472479 CallReducer {
473- reply_tx : oneshot :: Sender < WorkerReply < ReducerCallResult > > ,
480+ reply_tx : JsReplyTx < ReducerCallResult > ,
474481 params : CallReducerParams ,
475482 } ,
476483 CallView {
477- reply_tx : oneshot :: Sender < WorkerReply < ViewCommandResult > > ,
484+ reply_tx : JsReplyTx < ViewCommandResult > ,
478485 cmd : ViewCommand ,
479486 } ,
480487 CallProcedure {
481- reply_tx : oneshot :: Sender < WorkerReply < CallProcedureReturn > > ,
488+ reply_tx : JsReplyTx < CallProcedureReturn > ,
482489 params : CallProcedureParams ,
483490 } ,
484- ClearAllClients ( oneshot :: Sender < WorkerReply < anyhow:: Result < ( ) > > > ) ,
491+ ClearAllClients ( JsReplyTx < anyhow:: Result < ( ) > > ) ,
485492 CallIdentityConnected {
486- reply_tx : oneshot :: Sender < WorkerReply < Result < ( ) , ClientConnectedError > > > ,
493+ reply_tx : JsReplyTx < Result < ( ) , ClientConnectedError > > ,
487494 caller_auth : ConnectionAuthCtx ,
488495 caller_connection_id : ConnectionId ,
489496 } ,
490497 CallIdentityDisconnected {
491- reply_tx : oneshot :: Sender < WorkerReply < Result < ( ) , ReducerCallError > > > ,
498+ reply_tx : JsReplyTx < Result < ( ) , ReducerCallError > > ,
492499 caller_identity : Identity ,
493500 caller_connection_id : ConnectionId ,
494501 } ,
495502 DisconnectClient {
496- reply_tx : oneshot :: Sender < WorkerReply < Result < ( ) , ReducerCallError > > > ,
503+ reply_tx : JsReplyTx < Result < ( ) , ReducerCallError > > ,
497504 client_id : ClientActorId ,
498505 } ,
499506 InitDatabase {
500- reply_tx : oneshot :: Sender < WorkerReply < anyhow:: Result < Option < ReducerCallResult > > > > ,
507+ reply_tx : JsReplyTx < anyhow:: Result < Option < ReducerCallResult > > > ,
501508 program : Program ,
502509 } ,
503510 CallScheduledFunction {
504- reply_tx : oneshot :: Sender < WorkerReply < CallScheduledFunctionResult > > ,
511+ reply_tx : JsReplyTx < CallScheduledFunctionResult > ,
505512 params : ScheduledFunctionParams ,
506513 } ,
507514}
508515
509516static_assert_size ! ( CallReducerParams , 192 ) ;
510517
511- fn send_worker_reply < T > ( ctx : & str , reply_tx : oneshot :: Sender < WorkerReply < T > > , value : T , trapped : bool ) {
512- if reply_tx. send ( WorkerReply { value, trapped } ) . is_err ( ) {
518+ fn send_worker_reply < T > ( ctx : & str , reply_tx : JsReplyTx < T > , value : T , trapped : bool ) {
519+ if reply_tx. send ( JsWorkerReply { value, trapped } ) . is_err ( ) {
513520 log:: error!( "should have receiver for `{ctx}` response" ) ;
514521 }
515522}
0 commit comments