@@ -349,6 +349,11 @@ impl JsInstanceEnv {
349349/// and friends.
350350#[ derive( Clone ) ]
351351pub struct JsInstance {
352+ /// Stable identifier for the underlying worker generation.
353+ ///
354+ /// All clones of the same handle share the same `id`. The instance lane uses
355+ /// it to tell whether the currently active worker has already been replaced
356+ /// after a trap or disconnect.
352357 id : u64 ,
353358 request_tx : flume:: Sender < JsWorkerRequest > ,
354359 trapped : Arc < AtomicBool > ,
@@ -519,44 +524,57 @@ type JsReplyTx<T> = oneshot::Sender<JsWorkerReply<T>>;
519524/// executes the request there, and then has to send both the typed result and
520525/// the worker's trapped-bit back to the async caller.
521526enum JsWorkerRequest {
527+ /// See [`JsInstance::run_on_thread`].
528+ ///
529+ /// This variant does not expect a [`JsWorkerReply`].
522530 RunFunction ( Box < dyn FnOnce ( ) -> LocalBoxFuture < ' static , ( ) > + Send > ) ,
531+ /// See [`JsInstance::update_database`].
523532 UpdateDatabase {
524533 reply_tx : JsReplyTx < anyhow:: Result < UpdateDatabaseResult > > ,
525534 program : Program ,
526535 old_module_info : Arc < ModuleInfo > ,
527536 policy : MigrationPolicy ,
528537 } ,
538+ /// See [`JsInstance::call_reducer`].
529539 CallReducer {
530540 reply_tx : JsReplyTx < ReducerCallResult > ,
531541 params : CallReducerParams ,
532542 } ,
543+ /// See [`JsInstance::call_view`].
533544 CallView {
534545 reply_tx : JsReplyTx < ViewCommandResult > ,
535546 cmd : ViewCommand ,
536547 } ,
548+ /// See [`JsInstance::call_procedure`].
537549 CallProcedure {
538550 reply_tx : JsReplyTx < CallProcedureReturn > ,
539551 params : CallProcedureParams ,
540552 } ,
553+ /// See [`JsInstance::clear_all_clients`].
541554 ClearAllClients ( JsReplyTx < anyhow:: Result < ( ) > > ) ,
555+ /// See [`JsInstance::call_identity_connected`].
542556 CallIdentityConnected {
543557 reply_tx : JsReplyTx < Result < ( ) , ClientConnectedError > > ,
544558 caller_auth : ConnectionAuthCtx ,
545559 caller_connection_id : ConnectionId ,
546560 } ,
561+ /// See [`JsInstance::call_identity_disconnected`].
547562 CallIdentityDisconnected {
548563 reply_tx : JsReplyTx < Result < ( ) , ReducerCallError > > ,
549564 caller_identity : Identity ,
550565 caller_connection_id : ConnectionId ,
551566 } ,
567+ /// See [`JsInstance::disconnect_client`].
552568 DisconnectClient {
553569 reply_tx : JsReplyTx < Result < ( ) , ReducerCallError > > ,
554570 client_id : ClientActorId ,
555571 } ,
572+ /// See [`JsInstance::init_database`].
556573 InitDatabase {
557574 reply_tx : JsReplyTx < anyhow:: Result < Option < ReducerCallResult > > > ,
558575 program : Program ,
559576 } ,
577+ /// See [`JsInstance::call_scheduled_function`].
560578 CallScheduledFunction {
561579 reply_tx : JsReplyTx < CallScheduledFunctionResult > ,
562580 params : ScheduledFunctionParams ,
@@ -592,6 +610,11 @@ struct JsInstanceLaneState {
592610}
593611
594612#[ derive( Clone ) ]
613+ /// A single serialized execution lane for JS module work.
614+ ///
615+ /// Callers share one active [`JsInstance`] so hot requests stay on the same
616+ /// worker thread for locality. The lane only steps in on the rare path, where
617+ /// a trap or disconnect forces that active worker to be replaced.
595618pub struct JsInstanceLane {
596619 module : JsModule ,
597620 state : Arc < JsInstanceLaneState > ,
0 commit comments