feat: add fswatch, sysinfo, and udp demo scripts plus reorder manual sidebar links
Add three new example scripts demonstrating the fswatch, sysinfo, and udp modules with file watching, system metrics, and UDP echo server/client patterns. Reorder the manual API sidebar navigation to list modules alphabetically, removing deprecated entries like websocket, tls, net, json, regex, jinja, os, signal, subprocess, sqlite, and timer while adding argparse, dataset, fswatch, and html.
This commit is contained in:
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
import "fswatch" for FileWatcher, FsEvent
|
||||
import "timer" for Timer
|
||||
import "io" for File, FileFlags
|
||||
|
||||
var testFile = "/tmp/fswatch_test_%(Num.fromString("%(System.clock)".split(".")[1])).txt"
|
||||
|
||||
var f = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.create | FileFlags.truncate)
|
||||
f.writeBytes("initial", 0)
|
||||
f.close()
|
||||
|
||||
var watcher = FileWatcher.new(testFile)
|
||||
var received = []
|
||||
|
||||
watcher.start { |event|
|
||||
received.add(event)
|
||||
}
|
||||
|
||||
System.print(watcher.isActive) // expect: true
|
||||
|
||||
Timer.immediate {
|
||||
var f2 = File.openWithFlags(testFile, FileFlags.writeOnly | FileFlags.truncate)
|
||||
f2.writeBytes("modified", 0)
|
||||
f2.close()
|
||||
}
|
||||
|
||||
Timer.sleep(100)
|
||||
|
||||
System.print(received.count > 0) // expect: true
|
||||
System.print(received[0] is FsEvent) // expect: true
|
||||
|
||||
watcher.stop()
|
||||
System.print(watcher.isActive) // expect: false
|
||||
Reference in New Issue
Block a user