http-async

    gaato/http Transport over moonbitlang/async. Native, JS, and moonrun Wasm targets.

    http
    transport
    async
    client
    Download zip
    Author
    Version
    0.1.1
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    89

    Dependencies

    #gaato/http-async

    AsyncTransport and AsyncClock: the gaato/http Transport and Clock over moonbitlang/async, for native, JS, and linear-memory Wasm on moonrun.

    The Wasm backend uses MoonBit host APIs for sockets and TLS; it is not a browser or generic WASI transport. When using a moonrun --policy file, allow the destination host and port in net.connect. Loopback tests also need local socket bind permission. Native and Wasm share the HTTP implementation and connection/protocol error classification; JS uses fetch.

    AsyncTransport keeps a small keep-alive pool per origin (max_idle_per_origin, idle_max_ms), never queues concurrent requests, and replays a request once on a fresh connection when a reused one fails before the response head, but only for idempotent methods or requests carrying an Idempotency-Key. Call close() to drop parked connections.

    Unofficial and experimental. Source, issues and design notes: https://github.com/gaato/mbt-sdk

    AsyncClock

    pub struct AsyncClock {
    }

    A production clock backed by moonbitlang/async timers and wall time.
    impl Clock for AsyncClock

    AsyncClock::new

    fn AsyncClock::new() -> AsyncClock

    Creates an async clock.

    test {
    let _ = @adapter.AsyncClock::new()
    }

    AsyncClock::now_unix_ms

    fn AsyncClock::now_unix_ms(_self : AsyncClock) -> Int64

    Explicit clock methods backed by moonbitlang/async.

    AsyncClock::sleep

    async fn AsyncClock::sleep(_self : AsyncClock, milliseconds : Int) -> Unit noraise

    Explicit clock methods backed by moonbitlang/async.

    AsyncTransport

    pub struct AsyncTransport {
    // private fields
    }

    An HTTP transport with bounded IO operations and a small keep-alive pool.

    A connection returns to the pool only after its response body has been consumed in full and the server did not answer Connection: close. At most max_idle_per_origin connections are parked per origin, each for at most idle_max_ms; concurrent requests beyond that dial new connections and are never queued. When a reused connection fails before a response head, the request is sent once more on a fresh connection if it is idempotent or carries an Idempotency-Key; other requests surface the failure.

    AsyncTransport::close

    fn AsyncTransport::close(self : AsyncTransport) -> Unit

    Closes every idle connection and refuses further requests with Connect("transport closed"). In-flight requests finish and their connections are closed instead of parked.

    test {
    let transport = @adapter.AsyncTransport::new()
    transport.close()
    assert_eq(transport.idle_connections(), 0)
    }

    AsyncTransport::idle_connections

    fn AsyncTransport::idle_connections(self : AsyncTransport) -> Int

    The number of parked keep-alive connections across all origins.

    AsyncTransport::new

    fn AsyncTransport::new(timeout_ms? : Int, max_idle_per_origin? : Int, idle_max_ms? : Int) -> AsyncTransport

    Creates a transport. Streaming reads each receive a fresh idle timeout. max_idle_per_origin = 0 or idle_max_ms = 0 disables connection reuse.

    test {
    let _ = @adapter.AsyncTransport::new(timeout_ms=1000)
    let _ = @adapter.AsyncTransport::new(max_idle_per_origin=0)
    }

    AsyncTransport::send

    Explicit transport methods for buffered and streaming requests.

    AsyncTransport::send_stream

    Explicit transport methods for buffered and streaming requests.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io