pub fn poll_event_loop(
    &mut self,
    cx: &mut Context,
    wait_for_inspector: bool,
  ) -> Poll<Result<(), AnyError>> {
    // We always poll the inspector first
    let _ = self.inspector().poll_unpin(cx);

    let state_rc = Self::state(self.v8_isolate());
    let module_map_rc = Self::module_map(self.v8_isolate());
    {
      let state = state_rc.borrow();
      state.waker.register(cx.waker());
    }

    // Ops
    {
      let async_responses = self.poll_pending_ops(cx);
      self.async_op_response(async_responses)?;
      self.drain_macrotasks()?;
      self.check_promise_exceptions()?;
    }

    // Dynamic module loading - ie. modules loaded using "import()"
    {
      let poll_imports = self.prepare_dyn_imports(cx)?;
      assert!(poll_imports.is_ready());

      let poll_imports = self.poll_dyn_imports(cx)?;
      assert!(poll_imports.is_ready());

      self.evaluate_dyn_imports();

      self.check_promise_exceptions()?;
    }

    // Top level module
    self.evaluate_pending_module();

    let state = state_rc.borrow();
    let module_map = module_map_rc.borrow();

    let has_pending_ops = !state.pending_ops.is_empty();

    let has_pending_dyn_imports = module_map.has_pending_dynamic_imports();
    let has_pending_dyn_module_evaluation =
      !state.pending_dyn_mod_evaluate.is_empty();
    let has_pending_module_evaluation = state.pending_mod_evaluate.is_some();
    let inspector_has_active_sessions = self
      .inspector
      .as_ref()
      .map(|i| i.has_active_sessions())
      .unwrap_or(false);

    if !has_pending_ops
      && !has_pending_dyn_imports
      && !has_pending_dyn_module_evaluation
      && !has_pending_module_evaluation
    {
      if wait_for_inspector && inspector_has_active_sessions {
        return Poll::Pending;
      }

      return Poll::Ready(Ok(()));
    }

    // Check if more async ops have been dispatched
    // during this turn of event loop.
    if state.have_unpolled_ops {
      state.waker.wake();
    }

    if has_pending_module_evaluation {
      if has_pending_ops
        || has_pending_dyn_imports
        || has_pending_dyn_module_evaluation
      {
        // pass, will be polled again
      } else {
        let msg = "Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promise.";
        return Poll::Ready(Err(generic_error(msg)));
      }
    }

    if has_pending_dyn_module_evaluation {
      if has_pending_ops || has_pending_dyn_imports {
        // pass, will be polled again
      } else {
        let mut msg = "Dynamically imported module evaluation is still pending but there are no pending ops. This situation is often caused by unresolved promise.
Pending dynamic modules:\n".to_string();
        for pending_evaluate in &state.pending_dyn_mod_evaluate {
          let module_info = module_map
            .get_info_by_id(&pending_evaluate.module_id)
            .unwrap();
          msg.push_str(&format!("- {}", module_info.name.as_str()));
        }
        return Poll::Ready(Err(generic_error(msg)));
      }
    }

    Poll::Pending
  }
/// Runs a single tick of event loop
///
/// If `wait_for_inspector` is set to true event loop
/// will return `Poll::Pending` if there are active inspector sessions.
Runs a single tick of event loop
If `wait_for_inspector` is set to true event loop
will return `Poll::Pending` if there are active inspector sessions.
Runs a single tick of event loop If ` wait_for_inspector ` is set to true event loop will return ` Poll :: Pending ` if there are active inspector sessions .
pub fn poll_event_loop(
    &mut self,
    cx: &mut Context,
    wait_for_inspector: bool,
  ) -> Poll<Result<(), AnyError>> {
    // We always poll the inspector first
    let _ = self.inspector().poll_unpin(cx);
    let state_rc = Self::state(self.v8_isolate());
    let module_map_rc = Self::module_map(self.v8_isolate());
    {
      let state = state_rc.borrow();
      state.waker.register(cx.waker());
    }
    // Ops
    {
      let async_responses = self.poll_pending_ops(cx);
      self.async_op_response(async_responses)?;
      self.drain_macrotasks()?;
      self.check_promise_exceptions()?;
    }
    // Dynamic module loading - ie. modules loaded using "import()"
    {
      let poll_imports = self.prepare_dyn_imports(cx)?;
      assert!(poll_imports.is_ready());
      let poll_imports = self.poll_dyn_imports(cx)?;
      assert!(poll_imports.is_ready());
      self.evaluate_dyn_imports();
      self.check_promise_exceptions()?;
    }
    // Top level module
    self.evaluate_pending_module();
    let state = state_rc.borrow();
    let module_map = module_map_rc.borrow();
    let has_pending_ops = !state.pending_ops.is_empty();
    let has_pending_dyn_imports = module_map.has_pending_dynamic_imports();
    let has_pending_dyn_module_evaluation =
      !state.pending_dyn_mod_evaluate.is_empty();
    let has_pending_module_evaluation = state.pending_mod_evaluate.is_some();
    let inspector_has_active_sessions = self
      .inspector
      .as_ref()
      .map(|i| i.has_active_sessions())
      .unwrap_or(false);
    if !has_pending_ops
      && !has_pending_dyn_imports
      && !has_pending_dyn_module_evaluation
      && !has_pending_module_evaluation
    {
      if wait_for_inspector && inspector_has_active_sessions {
        return Poll::Pending;
      }
      return Poll::Ready(Ok(()));
    }
    // Check if more async ops have been dispatched
    // during this turn of event loop.
    if state.have_unpolled_ops {
      state.waker.wake();
    }
    if has_pending_module_evaluation {
      if has_pending_ops
        || has_pending_dyn_imports
        || has_pending_dyn_module_evaluation
      {
        // pass, will be polled again
      } else {
        let msg = "Module evaluation is still pending but there are no pending ops or dynamic imports. This situation is often caused by unresolved promise.";
        return Poll::Ready(Err(generic_error(msg)));
      }
    }
    if has_pending_dyn_module_evaluation {
      if has_pending_ops || has_pending_dyn_imports {
        // pass, will be polled again
      } else {
        let mut msg = "Dynamically imported module evaluation is still pending but there are no pending ops. This situation is often caused by unresolved promise.
Pending dynamic modules:\n".to_string();
        for pending_evaluate in &state.pending_dyn_mod_evaluate {
          let module_info = module_map
            .get_info_by_id(&pending_evaluate.module_id)
            .unwrap();
          msg.push_str(&format!("- {}", module_info.name.as_str()));
        }
        return Poll::Ready(Err(generic_error(msg)));
      }
    }
    Poll::Pending
  }
pub fn poll_event_loop ( & mut self , cx : & mut Context , wait_for_inspector : bool , ) -> Poll < Result < ( ) , AnyError > > { // We always poll the inspector first let _ = self . inspector ( ) . poll_unpin ( cx ) ; let state_rc = Self :: state ( self . v8_isolate ( ) ) ; let module_map_rc = Self :: module_map ( self . v8_isolate ( ) ) ; { let state = state_rc . borrow ( ) ; state . waker . register ( cx . waker ( ) ) ; } // Ops { let async_responses = self . poll_pending_ops ( cx ) ; self . async_op_response ( async_responses ) ? ; self . drain_macrotasks ( ) ? ; self . check_promise_exceptions ( ) ? ; } // Dynamic module loading - ie. modules loaded using "import()" { let poll_imports = self . prepare_dyn_imports ( cx ) ? ; assert ! ( poll_imports is_ready ( ) ) ; let poll_imports = self . poll_dyn_imports ( cx ) ? ; assert ! ( poll_imports is_ready ( ) ) ; self . evaluate_dyn_imports ( ) ; self . check_promise_exceptions ( ) ? ; } // Top level module self . evaluate_pending_module ( ) ; let state = state_rc . borrow ( ) ; let module_map = module_map_rc . borrow ( ) ; let has_pending_ops = ! state . pending_ops . is_empty ( ) ; let has_pending_dyn_imports = module_map . has_pending_dynamic_imports ( ) ; let has_pending_dyn_module_evaluation = ! state . pending_dyn_mod_evaluate . is_empty ( ) ; let has_pending_module_evaluation = state . pending_mod_evaluate . is_some ( ) ; let inspector_has_active_sessions = self . inspector . as_ref ( ) . map ( | i | i . has_active_sessions ( ) ) . unwrap_or ( false ) ; if ! has_pending_ops && ! has_pending_dyn_imports && ! has_pending_dyn_module_evaluation && ! has_pending_module_evaluation { if wait_for_inspector && inspector_has_active_sessions { return Poll :: Pending ; } return Poll :: Ready ( Ok ( ( ) ) ) ; } // Check if more async ops have been dispatched // during this turn of event loop. if state . have_unpolled_ops { state . waker . wake ( ) ; } if has_pending_module_evaluation { if has_pending_ops || has_pending_dyn_imports || has_pending_dyn_module_evaluation { // pass, will be polled again } else { let msg = " " ; return Poll :: Ready ( Err ( generic_error ( msg ) ) ) ; } } if has_pending_dyn_module_evaluation { if has_pending_ops || has_pending_dyn_imports { // pass, will be polled again } else { let mut msg = " \n " . to_string ( ) ; for pending_evaluate in & state . pending_dyn_mod_evaluate { let module_info = module_map . get_info_by_id ( & pending_evaluate . module_id ) . unwrap ( ) ; msg . push_str ( & format ! ( " " module_info name as_str ( ) ) ) ; } return Poll :: Ready ( Err ( generic_error ( msg ) ) ) ; } } Poll :: Pending }
Runs a single tick of event loop
If `wait_for_inspector` is set to true event loop
will return `Poll::Pending` if there are active inspector sessions.
Runs a single tick of event loop If ` wait_for_inspector ` is set to true event loop will return ` Poll :: Pending ` if there are active inspector sessions .
&mut self
cx
&mut Context
wait_for_inspector
bool
&mut self
cx
&mut Context
wait_for_inspector
bool