Skip to content

sparkles:event-horizon ​

Interactive CPU work uses raw_pool.RawCpuPool: a persistent bounded queue of closure-free jobs with completion delivery on the polling thread. RawJob requires an allocation-free callback; select CpuJob as the third pool template argument for allocating parsers. The caller owns each context through completion dispatch or shutdown/drain. Queue saturation is an explicit result; callbacks never disappear to make room for newer work. job_queue.JobQueue wraps that protocol for an application thread: submit a class with run(), get a ticket, and poll for finished jobs in submission order; shutdown runs or cancels what has not started.

sparkles:event-horizon is a completion-first event loop for D: io_uring on Linux, kqueue on macOS and the BSDs, IOCP on Windows (in progress), driven in three tiers — a callback loop, direct-style fibers with structured concurrency, and an Effect!T veneer — with process supervision, channels, retry schedules and a bounded pool for the few host calls a completion backend cannot express.

Use it when a program has to wait on many things at once — sockets, files, timers, child processes, signals — and you want that waiting to read as ordinary sequential code, with cancellation, timeouts and cleanup that cannot be forgotten.

On Windows, IOCP currently supports socket I/O, timers, cross-thread wakes and the scheduler-integrated BlockingPool. Cancellation uses CancelIoEx; the target's storage remains live until its terminal completion, and cancelAndWait consumes both the target and the cancellation acknowledgment. Port waits drain batches with GetQueuedCompletionStatusEx. An operation on a handle that another completion port owns fails with EINVAL, and Win32 and NTSTATUS failures map to the C runtime's errno values. Overlapped native pipe reads/writes are supported, including cancellation and EOF. Synchronous file/pipe handles are rejected with EINVAL before issuing I/O. Regular-file operations require explicit offsets: ulong.max (current position) is accepted only for pipes, not regular-file current-position or append operations. The asynchronous VFS open path, file flush and Windows process supervision remain incomplete; see M19 in the delivery plan below. Wine probes are smoke evidence, not native Windows certification.

OwnedFd and BorrowedFd carry NativeHandle: an int on POSIX and a full-width HANDLE on Windows. A Windows OwnedFd closes file, pipe and process handles with CloseHandle; it must not own a Winsock socket, which requires closesocket. The legacy socket views remain separate pending the owned-socket port. Read/write/flush operation descriptors use the same native file-handle type without narrowing.

On macOS, supervised resource samples use libproc (proc_pid_rusage V4 and child rosters). A bounded tree walk validates identities and rosters before committing CPU totals or memory/process peaks. Its entry budget counts each PID once per sample; its byte budget counts every returned rusage record and child PID, not unused roster-buffer capacity. Failed or budget-exhausted walks retain the preceding measurements and mark degradation; sampled peaks and tree CPU remain lower bounds. CPU counters are converted from Mach ticks with the host timebase, including non-unit Apple Silicon clocks. Shared POSIX parity probes exercise line framing, real samples, timeout escalation, cancellation and admission-failure cleanup. The complete macOS lifecycle edge-case matrix is still open.

d
import sparkles.event_horizon;
import core.time : msecs;

LoopGroup group;
if (LoopGroup.start(group).hasError)
    assert(false, "no completion backend");
scope (exit) group.shutdown();

auto outcome = group.run((ref RootScope sc, ref Env env) {
    cast(void) env.clock.sleep(10.msecs); // parks the fiber, not the thread
    return 42;
});
assert(outcome.value == 42);

How this documentation is organised ​

These docs follow the Diátaxis framework.

Tutorial ​

Learning-oriented.

  • Coming from Node.js — the event loop you already know, mapped concept by concept onto fibers, scopes, channels and supervised processes, with runnable programs for each.
  • Coming from eventcore — proactor drivers, callbacks, and handle ownership mapped to scoped fibers and I/O results.
  • Coming from vibe-core — direct-style fibers and task handles mapped to explicit scope ownership and cancellation.
  • Coming from libasync — comparing callback I/O, file workers, and cross-thread notifications with scoped I/O.
  • Coming from Photon — comparing Photon's syscall interception and fibers with explicit capabilities and scopes.
  • Coming from collie — Netty/Finagle-style channel pipelines and readiness loops compared with completion-first fibers, move-only buffers, and structured concurrency.
  • Coming from hunt-net — Java/Netty/Vert.x-inspired asynchronous networking, codecs, and connection handlers mapped to stream primitives.
  • Coming from EVE — layered backends and runtime facilities mapped to scoped fibers, outcomes, and bounded channels.
  • Running the examples — Linux prerequisites, executable shared examples, partial I/O, error handling, and support boundaries.

Reference ​

Information-oriented. The normative surface lives in the specification for now: SPEC.md (public API in §16) and the delivery status in PLAN.md.

Explanation ​

Understanding-oriented. The research behind the design: Async I/O & Event Loops and Process Supervision.