feat: add networking module with TCP Socket/Server and example applications
Implement a full-featured `net` module supporting TCP `Socket` and `Server` classes via libuv, including example applications (chat server, echo server, HTTP client/server, file explorer, system dashboard) and benchmark scripts (fibonacci, n-body). Add GEMINI.md project documentation and Stderr class to io module.
This commit is contained in:
Vendored
+51
@@ -0,0 +1,51 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
import "scheduler" for Scheduler
|
||||
import "timer" for Timer
|
||||
|
||||
class TaskQueue {
|
||||
construct new() {
|
||||
_tasks = []
|
||||
_running = true
|
||||
}
|
||||
|
||||
add(name, duration) {
|
||||
System.print("[Queue] Adding task: \%(name) (\%(duration)ms)")
|
||||
_tasks.add({
|
||||
System.print("[Worker] Starting \%(name)...")
|
||||
Timer.sleep(duration)
|
||||
System.print("[Worker] Finished \%(name).")
|
||||
})
|
||||
}
|
||||
|
||||
start() {
|
||||
System.print("[Queue] Starting task runner...")
|
||||
Fiber.new {
|
||||
while (_running) {
|
||||
if (!_tasks.isEmpty) {
|
||||
var task = _tasks.removeAt(0)
|
||||
task.call()
|
||||
}
|
||||
Timer.sleep(100) // Yield to other fibers
|
||||
}
|
||||
}.call()
|
||||
}
|
||||
|
||||
stop() { _running = false }
|
||||
}
|
||||
|
||||
var queue = TaskQueue.new()
|
||||
|
||||
// Start the worker in the background
|
||||
queue.start()
|
||||
|
||||
// Add some tasks from the main thread
|
||||
queue.add("Task A", 1500)
|
||||
queue.add("Task B", 500)
|
||||
queue.add("Task C", 1000)
|
||||
|
||||
System.print("[Main] All tasks queued. Main fiber is free.")
|
||||
|
||||
// Keep the main loop alive for a bit to see the output
|
||||
Timer.sleep(4000)
|
||||
queue.stop()
|
||||
System.print("[Main] Shutdown.")
|
||||
Reference in New Issue
Block a user