Skip to content

Conversation

jasnell
Copy link
Collaborator

@jasnell jasnell commented Aug 23, 2025

Scratching a long-time itch... implements a workerd::util::Queue<T> class that wraps std::list with a safer interface. Whereas std::list front() can be called without safety checks when the list is empty, returning a bad reference, the Queue<T> will return a kj::none when the queue is empty. A few other details:

  • The queue only permits movable types
  • Items can only be appended to the end of the queue
  • The traditional iterators are intentionally hidden to limit accidental mutations
  • References are not completely hidden or protected (e.g. there's still a peek() method that returns a kj::Maybe<T&> but overall the design should be safer.

This PR converts a number of the existing std::list uses. There are more to do, particularly in api/streams but I'll update those separately.

The whole motivation here is to have a safer-to-use alternative to standard containers.

@jasnell jasnell requested review from a team as code owners August 23, 2025 05:35
A wrapper around an std::list that implements
safety checks to ensure that queue queue is not
accessed incorrectly.
@jasnell jasnell requested a review from npaun August 25, 2025 21:44
@jasnell jasnell merged commit 190fce4 into main Aug 25, 2025
21 checks passed
@jasnell jasnell deleted the jasnell/checked-queue branch August 25, 2025 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants