This repository was archived by the owner on Apr 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
fix: event loop rewrite and libuv compat layer #1309
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
3811b92
event loop rewrite with libuv compat
littledivy 011a459
x
littledivy 9d40040
optimize
littledivy 473be7d
fmt + fix error numbers
nathanwhit 7c249e4
fix shutdown (slop)
nathanwhit cd01510
unslop
littledivy 0866915
delete .oc
littledivy a13cb59
fix errnos
nathanwhit 2d4afaf
Merge main into event-loop-rewrite-slop
nathanwhit 1b143d8
port async context fix
nathanwhit 61df153
fmt
nathanwhit d7f8230
appease linter
nathanwhit 0c40092
allow cancelling timers within the same batch
nathanwhit 72cd0cc
set receiver to globalThis during timer callbacks
nathanwhit 955912b
fix windows
littledivy 1eeb318
fix
littledivy c73ccc2
more fix
littledivy b01a03c
fmt
littledivy aa29ef1
trial
littledivy 1a673b8
more fixes
littledivy 58a0943
fix test on widnows
littledivy 1425fc7
cfg out some uv_compat tests on miri
nathanwhit e49e59f
appease miri
nathanwhit f476fe4
remmove libuv tests
littledivy 475d347
add safety comments
littledivy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Copyright 2018-2025 the Deno authors. MIT license. | ||
|
|
||
| //! Event loop phase state. | ||
| //! | ||
| //! The actual phase-based event loop is driven by `poll_event_loop_inner` in | ||
| //! `jsruntime.rs`. This module provides auxiliary state for phases that need | ||
| //! Rust-side callback queues (currently only close callbacks). | ||
| //! | ||
| //! libuv-style phases (timers, idle, prepare, poll, check) are driven | ||
| //! directly through `UvLoopInner` when a uv_loop is registered. | ||
|
|
||
| use std::collections::VecDeque; | ||
|
|
||
| /// Close callback for resource cleanup. | ||
| pub(crate) struct CloseCallback { | ||
| pub callback: Box<dyn FnOnce()>, | ||
| } | ||
|
|
||
| /// Phase-specific state for the event loop. | ||
| /// | ||
| /// Currently only tracks close callbacks. Other phase hooks (idle, prepare, | ||
| /// check) are handled by `UvLoopInner` for the libuv compat path. | ||
| #[derive(Default)] | ||
| pub(crate) struct EventLoopPhases { | ||
| /// Phase 6: Close callbacks. | ||
| pub close_callbacks: VecDeque<CloseCallback>, | ||
| } | ||
|
|
||
| impl EventLoopPhases { | ||
| /// Drain and run all close callbacks. | ||
| pub fn run_close_callbacks(&mut self) { | ||
| while let Some(cb) = self.close_callbacks.pop_front() { | ||
| (cb.callback)(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2018-2025 the Deno authors. MIT license. | ||
|
|
||
| //! Reactor abstraction for timer and I/O primitives. | ||
|
nathanwhit marked this conversation as resolved.
|
||
| //! | ||
| //! Currently used by [`WebTimers`](crate::web_timeout::WebTimers) to abstract | ||
| //! over the timer backend. The default implementation (`reactor-tokio` feature) | ||
| //! delegates to tokio. | ||
| //! | ||
| //! Note: `uv_compat` does **not** use this trait -- it talks to tokio directly | ||
| //! because it needs lower-level control (poll_accept, try_read, try_write). | ||
|
|
||
| use std::future::Future; | ||
| use std::ops::Add; | ||
| use std::pin::Pin; | ||
| use std::task::Context; | ||
| use std::task::Poll; | ||
| use std::time::Duration; | ||
|
|
||
| /// Abstraction over the async I/O reactor (tokio, mio, io_uring, custom). | ||
| /// This is the only seam between deno_core and the underlying async runtime. | ||
| pub trait Reactor: 'static { | ||
| type Timer: ReactorTimer; | ||
| type Instant: ReactorInstant; | ||
|
|
||
| /// Create a new one-shot timer that fires at the given instant. | ||
| fn timer(&self, deadline: Self::Instant) -> Self::Timer; | ||
|
|
||
| /// Get the current instant. | ||
| fn now(&self) -> Self::Instant; | ||
|
|
||
| /// Poll the reactor for I/O readiness. This is called during the "poll" phase. | ||
| /// Drives the underlying event source (epoll/kqueue/iocp). | ||
| /// `timeout` = None means block indefinitely, Some(Duration::ZERO) means non-blocking. | ||
| fn poll(&self, cx: &mut Context, timeout: Option<Duration>) -> Poll<()>; | ||
|
|
||
| /// Spawn a future onto the reactor's executor (if it has one). | ||
| /// Returns a handle that can be polled for the result. | ||
| fn spawn( | ||
| &self, | ||
| fut: Pin<Box<dyn Future<Output = ()> + 'static>>, | ||
| ) -> Pin<Box<dyn Future<Output = ()>>>; | ||
| } | ||
|
|
||
| /// A timer future that can be reset to fire at a different deadline. | ||
| pub trait ReactorTimer: Future<Output = ()> + Unpin { | ||
| fn reset(&mut self, deadline: impl Into<Self::Instant>) | ||
| where | ||
| Self: Sized; | ||
|
|
||
| type Instant: ReactorInstant; | ||
|
|
||
| /// The deadline this timer is set to fire at. | ||
| fn deadline(&self) -> Self::Instant; | ||
| } | ||
|
|
||
| /// An instant in time, used for timer deadlines. | ||
| pub trait ReactorInstant: | ||
| Copy + Ord + Add<Duration, Output = Self> + Send + Sync + 'static | ||
| { | ||
| fn now() -> Self; | ||
| fn elapsed(&self) -> Duration; | ||
| fn checked_add(&self, duration: Duration) -> Option<Self>; | ||
| } | ||
|
|
||
| /// The default reactor type, selected by feature flags. | ||
| /// When `reactor-tokio` is enabled, this is `TokioReactor`. | ||
| #[cfg(feature = "reactor-tokio")] | ||
| pub type DefaultReactor = crate::reactor_tokio::TokioReactor; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.