Repository navigation
Add blocking mode support for file operations - #286
Conversation
This allows file operations to be used in synchronous code without requiring an async runtime initialization. Changes: - Add src/ev/blocking.zig for synchronous I/O execution - Update waitForIo() to auto-detect blocking context - Add waitForIoUncancelable() for cleanup operations - Update close() methods to use waitForIoUncancelable() When called without a Runtime, file operations now execute synchronously using blocking syscalls. When called within a Runtime context, they continue to use the event loop as before. Supported in blocking mode: - All file operations (read, write, open, close, stat, sync, etc.) - All directory operations - Pipe create/close Not supported in blocking mode (require event loop): - Network operations - Pipe read/write - Timers and async primitives
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds uncancelable blocking I/O support: new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This PR adds support for using file operations in synchronous code without requiring an async runtime.
Summary
File operations can now be used in regular blocking code. When called without a
Runtime, operations execute synchronously using blocking syscalls. When called within aRuntimecontext, they continue to use the async event loop as before.Changes
src/ev/blocking.zig- Provides synchronous I/O executionsrc/common.zig-waitForIo()auto-detects blocking context, addedwaitForIoUncancelable()src/fs.zig- Close methods now usewaitForIoUncancelable()src/ev/root.zig- ExportexecuteBlockingfunctionWhat Works in Blocking Mode
✅ All file operations (read, write, open, close, stat, sync, setSize, etc.)
✅ All directory operations (openDir, createDir, deleteDir, rename, etc.)
✅ Pipe create/close
What Doesn't Work in Blocking Mode
❌ Network operations (require event loop)
❌ Pipe read/write (require non-blocking I/O)
❌ Timers and async primitives (require event loop)
Example Usage
Testing
Notes
std.heap.smp_allocator