json
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
- parse & stringify
- Dot-path access
- Deep merge
- Pretty-print
Threading & Concurrency
Core Standard Library
parallel is how you use multiple cores from Niao. Spawn OS threads with a closure, guard shared state with a mutex, or pass work through channels between producers and consumers.
Thread pools accept a batch of jobs and run them on a fixed number of workers. Poll helpers let the VM kick off background work and check completion without blocking the main bytecode loop, important when you're mixing CPU work with I/O.
Import
import "parallel" |
Quick start
import "parallel" |
|
let pool = parallel.thread_pool(4) |
pool.submit(fn() { print("worker running") }) |
pool.wait_all() |
High-level overview of what parallel is for.
thread.spawn runs a closure on a new OS thread. mutex wraps shared data so only one thread mutates it at a time.
Bounded or unbounded queues for sending messages between threads, classic producer/consumer setup.
Fixed thread count, submit jobs, wait for the batch to finish. Simpler than managing threads by hand.
Start work in the background and poll from the main loop so the runtime can interleave other tasks.
25 functions and methods in parallel. Grouped by category from the standard library docs.
| Signature | Description |
|---|---|
| spawn(fn, ...args) | Start a thread running a Niao function |
| join(handle) | Wait for result |
| detach(handle) | Detach without joining |
| is_alive(handle) | Whether thread is still running |
| yield() | Hint scheduler |
| sleep(ms) | Sleep current thread |
| Signature | Description |
|---|---|
| new(initial?) | Create mutex with optional initial value |
| lock(handle) | Acquire lock |
| unlock(handle) | Release lock |
| try_lock(handle) | Non-blocking lock attempt → `bool` |
| get(handle) | Read value (locked or auto-lock) |
| set(handle, val) | Write value |
| run(handle, fn) | Lock, call `fn()`, unlock |
| Signature | Description |
|---|---|
| new(capacity?) | Unbounded if omitted; bounded if capacity > 0 |
| send(ch, val) | Send value |
| recv(ch) | Blocking receive |
| try_recv(ch) | Non-blocking receive (`nil` if empty) |
| recv_timeout(ch, ms) | Timed receive |
| close(ch) | Close channel |
| is_closed(ch) | Whether channel is closed |
| Signature | Description |
|---|---|
| new(workers) | Create pool with N worker threads |
| submit(pool, fn, ...args) | Queue work → task id |
| wait(pool, task_id) | Block for result |
| shutdown(pool) | Stop workers |
| active(pool) | Running task count |
More from Core Standard Library.
JSON Parse & Manipulate
Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.
File & Path I/O
Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.
Wall-Clock & Time Zones
Timestamps, formatting, parsing, and time zones. Built on chrono and chrono-tz, DST handled correctly.