Event loop system
The event loop is the heart of LibCore, enabling asynchronous I/O and event handling. See the event loop architecture for more details.Creating and running an event loop
There is at most one running event loop per thread. Event loops can be nested for modal dialogs and other temporary UI states.
Event loop capabilities
Deferred invocation
Execute callbacks on next event loop iteration
Timers
Schedule callbacks to run after delays or repeatedly
I/O notifications
React when file descriptors become readable/writable
Signal handling
Handle POSIX signals in event-driven manner
How it works
The event loop usesselect(2) to efficiently wait for events:
exec()repeatedly callspump()to process eventspump()usesselect()to sleep until an event occurs- When awakened, callbacks for expired timers and I/O are invoked
- The loop returns to sleep until the next event
Timers
Core::Timer
Schedule callbacks to run after a delay:I/O and notifications
Core::Notifier
React when file descriptors become readable or writable:Read- File descriptor has data to readWrite- File descriptor is ready for writingException- Exception condition occurred
File system operations
Core::File
Cross-platform file I/O:Core::Directory
Directory operations:Core::DirIterator
Iterate over directory entries:File watching
Monitor file system changes:Networking
Core::Socket
Base class for network sockets with async I/O:Core::TCPServer
TCP server with event-driven connection handling:Core::UDPServer
UDP socket for connectionless communication:Process management
Core::Process
Spawn and manage child processes:Environment and system info
Environment variables
Standard paths
Platform abstraction
LibCore provides cross-platform abstractions for:- File I/O: Works on Linux, macOS, Windows (WSL), and Unix systems
- Networking: Portable socket API across platforms
- Process management: Unified process spawning and control
- Event loops: Platform-specific implementations (
EventLoopImplementationUnix,EventLoopImplementationWindows)
Resource loading
Core::Resource
Load embedded or file-based resources:Promises and async operations
Core::Promise
Type-safe async value resolution:Core::ThreadedPromise
Promise that resolves on a background thread:Configuration files
Core::ConfigFile
INI-style configuration file handling:Argument parsing
Core::ArgsParser
User-friendly command-line argument parsing:Source location
- Repository:
~/workspace/source/Libraries/LibCore/ - Key headers:
EventLoop.h,Timer.h,File.h,Socket.h,Process.h - Documentation:
~/workspace/source/Documentation/EventLoop.md - Platform code:
LibCore/Platform/
LibCore’s event loop is designed for I/O-bound operations and UI events. For CPU-intensive work, use LibThreading to run tasks on background threads.