diff options
Diffstat (limited to 'monoio/src/runtime.rs')
| -rw-r--r-- | monoio/src/runtime.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/monoio/src/runtime.rs b/monoio/src/runtime.rs index d85f838..d5c0cfa 100644 --- a/monoio/src/runtime.rs +++ b/monoio/src/runtime.rs @@ -149,7 +149,7 @@ impl<D> Runtime<D> { Self { context, driver } } - /// 阻塞给定的 future + /// 主循环入口 pub fn block_on<F>(&mut self, future: F) -> F::Output where F: Future, @@ -166,20 +166,20 @@ impl<D> Runtime<D> { self.driver.with(|| { CURRENT.set(&self.context, || { - #[cfg(feature = "sync")] - let join = unsafe { spawn_without_static(future) }; - #[cfg(not(feature = "sync"))] + // #[cfg(feature = "sync")] + // let join = unsafe { spawn_without_static(future) }; + // #[cfg(not(feature = "sync"))] // join = future let join = future; let mut join = std::pin::pin!(join); - set_poll(); + set_poll(); // 设置 SHOULD_POLL true loop { loop { // Consume all tasks(with max round to prevent io starvation) // 消费所有 task (最大轮数防止 io 饥饿) let mut max_round = self.context.tasks.len() * 2; // Maximum round | Force exit when reaching the maximum round while let Some(t) = self.context.tasks.pop() { - t.run(); // 执行任务 + t.run(); // 执行任务 运行 (x.poll) // 避免无限循环 if max_round == 0 { // maybe there's a looping task @@ -190,7 +190,7 @@ impl<D> Runtime<D> { } } - // Check main future + // Check main future | 这里才第一次运行 join while should_poll() { // check if ready if let std::task::Poll::Ready(t) = join.as_mut().poll(cx) { @@ -206,13 +206,12 @@ impl<D> Runtime<D> { break; } // Cold path | 到这一步比较少 - // 待定 let _ = self.driver.submit(); } // Wait and Process CQ(the error is ignored for not debug mode) #[cfg(not(all(debug_assertions, feature = "debug")))] - let _ = self.driver.park(); // 无限等待并处理返回的事件 ?? + let _ = self.driver.park(); // 无限等待并处理返回的事件 #[cfg(all(debug_assertions, feature = "debug"))] if let Err(e) = self.driver.park() { |
