Skip to content

Commit a562f7c

Browse files
committed
random
1 parent 8b5ad83 commit a562f7c

File tree

1 file changed

+29
-24
lines changed

1 file changed

+29
-24
lines changed

core/inspector.rs

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ impl JsRuntimeInspectorState {
213213

214214
loop {
215215
// current_state -> PollState::Polling
216-
// starts polling for session_rx -> must be non-ready
217-
// self.established is empty - must be pending/poll::ready(None)
216+
// starts polling for new_io_session_rx -> must be non-ready
217+
// self.io_session_futures is empty - must be pending/poll::ready(None)
218218
sessions.pump_messages_for_remote_sessions(cx);
219219

220220
// current_state -> PollState::Polling
@@ -285,7 +285,8 @@ impl JsRuntimeInspector {
285285
context: v8::Local<v8::Context>,
286286
is_main_runtime: bool,
287287
) -> Rc<Self> {
288-
let (new_session_tx, new_session_rx) = mpsc::unbounded::<NewSessionTxMsg>();
288+
let (new_session_tx, new_new_io_session_rx) =
289+
mpsc::unbounded::<NewSessionTxMsg>();
289290

290291
let waker = InspectorWaker::new(scope.thread_safe_handle());
291292

@@ -308,7 +309,7 @@ impl JsRuntimeInspector {
308309

309310
*state.sessions.borrow_mut() = SessionContainer::new(
310311
v8_inspector.clone(),
311-
new_session_rx,
312+
new_new_io_session_rx,
312313
state.is_dispatching_message.clone(),
313314
);
314315

@@ -320,7 +321,7 @@ impl JsRuntimeInspector {
320321
});
321322

322323
inspector.context_created(context, is_main_runtime);
323-
// TODO(bartlomieju): we need to only poll `session_rx` once - just
324+
// TODO(bartlomieju): we need to only poll `new_io_session_rx` once - just
324325
// to register the task context, at this point it's guaranteed there are
325326
// senders, so no need to call the complicated `poll_sessions`.
326327

@@ -404,7 +405,7 @@ impl JsRuntimeInspector {
404405
}
405406

406407
/// This function blocks the thread until at least one inspector client has
407-
/// established a websocket connection.
408+
/// io_session_futures a websocket connection.
408409
pub fn wait_for_session(&self) {
409410
loop {
410411
if let Some(_session) =
@@ -420,15 +421,14 @@ impl JsRuntimeInspector {
420421
}
421422

422423
/// This function blocks the thread until at least one inspector client has
423-
/// established a websocket connection.
424+
/// io_session_futures a websocket connection.
424425
///
425426
/// After that, it instructs V8 to pause at the next statement.
426427
/// Frontend must send "Runtime.runIfWaitingForDebugger" message to resume
427428
/// execution.
428429
pub fn wait_for_session_and_break_on_next_statement(&self) {
429430
loop {
430-
if let Some(session) =
431-
self.state.sessions.borrow_mut().local.values().next()
431+
if let Some(session) = self.state.sessions.borrow().local.values().next()
432432
{
433433
break session.break_on_next_statement();
434434
} else {
@@ -488,23 +488,28 @@ pub struct SessionsState {
488488
/// parts of their lifecycle.
489489
pub struct SessionContainer {
490490
v8_inspector: Option<Rc<v8::inspector::V8Inspector>>,
491-
session_rx: UnboundedReceiver<NewSessionTxMsg>,
491+
492492
is_dispatching_message: Rc<RefCell<bool>>,
493-
established: FuturesUnordered<InspectorSessionPumpMessages>,
493+
494+
// These two are purely remote/IO sessions related
495+
new_io_session_rx: UnboundedReceiver<NewSessionTxMsg>,
496+
io_session_futures: FuturesUnordered<InspectorSessionPumpMessages>,
497+
498+
// These two are actually sessions
494499
next_local_id: i32,
495500
local: HashMap<i32, Rc<InspectorSession>>,
496501
}
497502

498503
impl SessionContainer {
499504
fn new(
500505
v8_inspector: Rc<v8::inspector::V8Inspector>,
501-
new_session_rx: UnboundedReceiver<NewSessionTxMsg>,
506+
new_new_io_session_rx: UnboundedReceiver<NewSessionTxMsg>,
502507
is_dispatching_message: Rc<RefCell<bool>>,
503508
) -> Self {
504509
Self {
505510
v8_inspector: Some(v8_inspector),
506-
session_rx: new_session_rx,
507-
established: FuturesUnordered::new(),
511+
new_io_session_rx: new_new_io_session_rx,
512+
io_session_futures: FuturesUnordered::new(),
508513
next_local_id: 1,
509514
local: HashMap::new(),
510515
is_dispatching_message,
@@ -517,13 +522,13 @@ impl SessionContainer {
517522
/// all sessions before dropping the inspector instance.
518523
fn drop_sessions(&mut self) {
519524
self.v8_inspector = Default::default();
520-
self.established.clear();
525+
self.io_session_futures.clear();
521526
self.local.clear();
522527
}
523528

524529
fn sessions_state(&self) -> SessionsState {
525530
SessionsState {
526-
has_active: !self.established.is_empty() || !self.local.is_empty(),
531+
has_active: !self.io_session_futures.is_empty() || !self.local.is_empty(),
527532
has_blocking: self
528533
.local
529534
.values()
@@ -550,8 +555,8 @@ impl SessionContainer {
550555
let (_tx, rx) = mpsc::unbounded::<NewSessionTxMsg>();
551556
Self {
552557
v8_inspector: Default::default(),
553-
session_rx: rx,
554-
established: FuturesUnordered::new(),
558+
new_io_session_rx: rx,
559+
io_session_futures: FuturesUnordered::new(),
555560
next_local_id: 1,
556561
local: HashMap::new(),
557562
is_dispatching_message: Default::default(),
@@ -592,23 +597,23 @@ impl SessionContainer {
592597
fn pump_messages_for_remote_sessions(&mut self, cx: &mut Context) {
593598
loop {
594599
// Accept new connections.
595-
let poll_result = self.session_rx.poll_next_unpin(cx);
600+
let poll_result = self.new_io_session_rx.poll_next_unpin(cx);
596601
if let Poll::Ready(Some(new_session_msg)) = poll_result {
597602
let (callback, rx, kind) = new_session_msg;
598603
let session = self.create_new_session(callback, kind);
599604

600605
let mut fut =
601606
pump_inspector_session_messages(session, rx).boxed_local();
602607
let _ = fut.poll_unpin(cx);
603-
self.established.push(fut);
608+
self.io_session_futures.push(fut);
604609

605-
// TODO(bartlomieju): decide on this - should we drain the `session_rx` queue fully
606-
// before polling `established` sessions?
610+
// TODO(bartlomieju): decide on this - should we drain the `new_io_session_rx` queue fully
611+
// before polling `io_session_futures` sessions?
607612
continue;
608613
}
609614

610-
// Poll established sessions.
611-
match self.established.poll_next_unpin(cx) {
615+
// Poll io_session_futures sessions.
616+
match self.io_session_futures.poll_next_unpin(cx) {
612617
Poll::Ready(Some(())) => {
613618
continue;
614619
}

0 commit comments

Comments
 (0)