Skip to content

Examples ​

Every example lives in examples/ and is compile-checked at build time (-DQZ_BUILD_EXAMPLES=ON). C examples are built by CMake; JS examples run via the qzjs CLI. Each example directory has a README.md with its exact run command and expected output.

Run examples against a Release build. A QZ_BUILD_TESTS=ON build links the core against mock_libuv, whose idle path blocks in a fixed 1-second poll fallback instead of waking at the timer's due time — timers therefore fire quantized to whole seconds. timers will print wrong elapsed times there. Production/Release builds use real libuv and are unaffected.

Building ​

bash
cmake -B build -DCMAKE_BUILD_TYPE=Release -DQZ_BUILD_EXAMPLES=ON
cmake --build build --parallel

C examples (embedding) ​

ExampleWhat it showsRun
helloMinimal embed: create runtime, eval JS, host↔JS message round-trip./build/examples/hello/qz_hello
messagesJSON request/response state machine (echo/add/date)./build/examples/messages/qz_messages
workernew Worker(url) parallel execution./build/examples/worker/qz_worker

C examples spawn qzjs-rt (ISOLATED process model); the build injects the runtime path automatically, so they run as-is.

JS examples (CLI) ​

ExampleWhat it showsRun
wasmExecute a WebAssembly module (WebAssembly.instantiate)./build/qzjs examples/wasm/wasm.js
cryptoWebCrypto: SHA-256 + AES-GCM encrypt/decrypt./build/qzjs examples/crypto/crypto.js
httpserverPure-JS serve() HTTP server with static files./build/qzjs examples/httpserver/server.js
websocketWebSocket echo server via serve() ws routes./build/qzjs examples/websocket/websocket.js
timerssetTimeout/setInterval + Promise.all async./build/qzjs examples/timers/timers.js
fsqzjs.fs read/write/list/unlink./build/qzjs examples/fs/fs.js
broadcastBroadcastChannel cross-instance messaging./build/qzjs examples/broadcast/broadcast.js
stream-pipelineReadableStream/TransformStream pipeline./build/qzjs examples/stream-pipeline/pipeline.js
fetch-proxyOutbound fetch proxy./build/qzjs examples/fetch-proxy/main.js
grpc-hellogRPC unary server (-DQZ_WITH_GRPC=ON)./build/qzjs examples/grpc-hello/grpc-hello.js
worker-orchestrateOrchestrate multiple workers./build/qzjs examples/worker-orchestrate/orchestrate.js

C extension ​

ExampleWhat it showsRun
extensionCompile a C extension into qzjs and expose a native global to JSsee extension/README.md

Extensions must be compiled into the qzjs library (-DQZ_EXTRA_SOURCES + -DQZ_EXTENSIONS + -DQZ_EXTRA_HEADERS); the example documents the exact build command.

MIT Licensed