package matryoshka-http-template:examples

⌘K
Ctrl+K
or
/

    Overview

    Echo example: single-worker pipeline that echoes the HTTP request body back.

    Architecture: HTTP POST /echo → bridge → worker → bridge → HTTP 200 body

    The worker receives a Message and sends it back to msg.reply_to unchanged. This is the simplest possible pipeline: one stage, no translation.

    Usage from tests: app := example_echo_start(8080, context.allocator) // ... send requests ... example_echo_stop(app)

    Multi-worker example: N workers sharing a single mailbox (MPMC pattern).

    Architecture: producer → shared_mailbox → [worker_1, worker_2, ... worker_N] → result

    This example does not involve HTTP — it demonstrates the MPMC concurrency pattern from matryoshka/examples/block2/fan_in_out.odin using the unified Master model and Stage_Fn callbacks.

    Usage from tests: ok := example_multi_worker(3)

    Full pipeline example: translator_in → worker → translator_out.

    Architecture: HTTP POST /pipeline → bridge → translator_in → worker → translator_out → bridge → HTTP 200

    translator_in: receives Message from bridge, passes it to the worker mailbox. worker: receives Message, processes payload (uppercases body), forwards to translator_out. translator_out: receives processed Message, sends it back to reply_to (the bridge).

    This example demonstrates the unified Master model: all three stages use the same Master struct and stage_proc — only the Stage_Fn callback changes.

    Usage from tests: app := example_pipeline_start(8081, context.allocator) // ... send requests ... example_pipeline_stop(app)

    Index

    Types (2)
    Constants (1)
    Variables (0)

    This section is empty.

    Procedure Groups (0)

    This section is empty.

    Types

    EchoApp ¶

    EchoApp :: struct {
    	server:        http.Server,
    	server_thread: ^thread.Thread,
    	serve_ctx:     ^Echo_Serve_Ctx,
    	router:        http.Router,
    	handler_data:  adapter_http.Handler_Data,
    	bridge:        adapter_http.Bridge,
    	pipeline:      pipeline.EchoPipeline,
    	stage_thread:  ^thread.Thread,
    	alloc:         runtime.Allocator,
    	// Actual listening port
    	port:          runtime.Maybe($T=int),
    }
     

    EchoApp holds all resources for the echo example server.

    Related Procedures With Parameters
    Related Procedures With Returns

    PipelineApp ¶

    PipelineApp :: struct {
    	server:        http.Server,
    	server_thread: ^thread.Thread,
    	serve_ctx:     ^Pipeline_Serve_Ctx,
    	router:        http.Router,
    	handler_data:  adapter_http.Handler_Data,
    	bridge:        adapter_http.Bridge,
    	pipeline:      pipeline.FullPipeline,
    	stage_threads: [3]^thread.Thread,
    	alloc:         runtime.Allocator,
    }
     

    PipelineApp holds all resources for the full-pipeline example server.

    Related Procedures With Parameters
    Related Procedures With Returns

    Constants

    ITEM_COUNT ¶

    ITEM_COUNT :: 10
     

    ITEM_COUNT is the number of items processed per example_multi_worker call.

    Variables

    This section is empty.

    Procedures

    echo_worker ¶

    echo_worker :: proc(me: ^pipeline.Master, _: ^matryoshka.PolyNode, mi: ^runtime.Maybe($T=^PolyNode)) {…}
     

    echo_worker is the processing callback for the echo stage. It receives a Message and sends it back to msg.reply_to unchanged.

    example_echo_start ¶

    example_echo_start :: proc(port: untyped integer, alloc: runtime.Allocator) -> ^EchoApp {…}
     

    example_echo_start wires the echo pipeline and starts an HTTP server on the given port. Returns nil if any setup step fails; example_echo_stop is safe to call on nil. The server is ready to accept connections when this function returns.

    example_echo_stop ¶

    example_echo_stop :: proc(app: ^EchoApp) {…}
     

    example_echo_stop shuts down the echo server and frees all resources. Safe to call on nil and on a partially-initialised app (error path from example_echo_start).

    example_multi_worker ¶

    example_multi_worker :: proc(n: untyped integer, alloc: runtime.Allocator) -> bool {…}
     

    example_multi_worker runs ITEM_COUNT items through n parallel workers sharing one mailbox. Returns true if all items were processed. Adapted from block2/fan_in_out.odin using unified Master + Stage_Fn.

    example_pipeline_start ¶

    example_pipeline_start :: proc(port: untyped integer, alloc: runtime.Allocator) -> ^PipelineApp {…}
     

    example_pipeline_start wires the three-stage pipeline and starts an HTTP server. Returns nil if any setup step fails; example_pipeline_stop is safe to call on nil.

    example_pipeline_stop ¶

    example_pipeline_stop :: proc(app: ^PipelineApp) {…}
     

    example_pipeline_stop shuts down the server and frees all resources. Safe to call on nil and on a partially-initialised app (error path from example_pipeline_start).

    pipeline_translate_in ¶

    pipeline_translate_in :: proc(me: ^pipeline.Master, next: ^matryoshka.PolyNode, mi: ^runtime.Maybe($T=^PolyNode)) {…}
     

    pipeline_translate_in forwards the Message to the worker mailbox without modification.

    pipeline_translate_out ¶

    pipeline_translate_out :: proc(me: ^pipeline.Master, _: ^matryoshka.PolyNode, mi: ^runtime.Maybe($T=^PolyNode)) {…}
     

    pipeline_translate_out sends the processed Message back to the bridge via reply_to.

    pipeline_worker ¶

    pipeline_worker :: proc(me: ^pipeline.Master, next: ^matryoshka.PolyNode, mi: ^runtime.Maybe($T=^PolyNode)) {…}
     

    pipeline_worker uppercases the payload, demonstrating domain processing.

    Procedure Groups

    This section is empty.

    Source Files