CodeVetter · Repo Unpack · Data flow
tokio-rs/tokio
Inputs enter as futures, addresses, buffers, channel values, paths, or subprocess commands. Runtime handles and registered I/O state connect pending work to scheduler wakeups. Channels and codecs own intermediate memory, while files and processes connect that memory to external resources. Completion returns through Future, Stream, JoinHandle, and standard I/O result types.
- spawn accepts a Send + 'static future and output, optionally boxes the future, assigns a task ID, and submits through the current runtime handle.
- String socket addresses first attempt direct SocketAddr parsing; unresolved strings are owned and resolved through std::net::ToSocketAddrs on spawn_blocking.
- PollEvented creates Registration against the current scheduler; add_source allocates ScheduledIo, registers its token with Mio, and removes allocation if registration fails.
- The I/O driver polls Mio events, translates readiness, updates ScheduledIo, and wakes interested tasks; socket reads then advance initialized bytes in ReadBuf.
- Bounded mpsc owns a semaphore sized to channel capacity; send awaits a permit before publishing, and ReceiverStream forwards stream polling to Receiver::poll_recv.
- Broadcast stores each value once and clones for receivers; its rounded power-of-two ring overwrites oldest values and reports skipped messages through RecvError::Lagged.
- LengthDelimitedCodec parses a header, validates and adjusts its length, reserves BytesMut capacity, then splits a complete payload and resets from Data to Head.
- Filesystem fallback moves an owned path and buffer into std::fs::write; subprocess output concurrently joins exit status with stdout/stderr reads into Vec buffers.