4 Application Backend
| (require rivet) | package: rivet |
4.1 RPCs, Events, State, Records, and Enums
struct
(struct rivet-type (name))
name : symbol?
Represents a public schema type descriptor.
value
value
value
value
value
value
struct
(struct state-info (name type cell lock))
name : symbol? type : any/c cell : box? lock : semaphore?
Represents a registered shared state value. Applications normally create one
with define-state instead of calling the constructor directly.
struct
(struct record-info (name field-names field-types))
name : symbol? field-names : list? field-types : list?
Represents the ordered schema of a named Record. Applications normally create
one with define-record instead of calling the constructor directly.
Represents the ordered cases of a named Enum. Applications normally create one
with define-enum instead of calling the constructor directly.
syntax
(define-rpc (name [arg : type] ... : result-type) body ...)
Defines a Racket procedure named name and registers it as an RPC for
generated Swift, C++, and Kotlin clients. Supported schema types are String,
Int64, Bool, Bytes, Void, Any,
(List type), (Optional type), and names introduced by
define-record or define-enum. The result is validated before
it is placed on the wire.
syntax
(define-record name ([field : field-type] ...))
Defines a constructor named name and registers an ordered, typed
Record schema. Records generate Swift and C++ structs plus Kotlin data classes
and use an RVT1 List in field declaration order.
Returns a named field from a value constructed by define-record.
syntax
(define-enum name (case ...))
Defines a constructor named name and registers a closed, ordered set
of cases. The constructor accepts a case symbol or string. Generated Swift uses
a raw-value enum; generated C++ uses enum class; generated Kotlin uses an
enum class with the wire name; RVT1 carries the stable case name as a
String.
Returns the case symbol from a value constructed by define-enum.
syntax
(define-event name : type)
Registers an event and defines name as a one-argument procedure that
emits a validated event value while a Rivet server is active. Omitting the type
uses Any. Event payloads cannot have type Void.
syntax
(define-state name : type initial-value)
Creates and registers a shared state value. Native clients can read and set the
state through generated APIs, and successful changes emit Rivet’s reserved
state event. State values cannot have type Void.
Emits an already registered event value on the active server connection. The
procedure reports an error when no server is active on the current thread.
procedure
state : state-info?
Returns the current state value.
procedure
(state-set! state value) → void?
state : state-info? value : any/c
Validates and atomically commits a state value, then admits its native event in
the same update order.
(require rivet) (define-rpc (greet [name : String] : String) (string-append "Hello, " name)) (define-event notification : String) (define-state signed-in? : Bool #f)
4.2 Serving an Embedded Connection
procedure
(serve in out [ #:max-pending-requests max-pending-requests #:max-outgoing-frames max-outgoing-frames]) → void? in : input-port? out : output-port? max-pending-requests : exact-positive-integer? = 1024 max-outgoing-frames : exact-positive-integer? = 64
Runs the RVT1 backend over binary ports. Requests execute concurrently within
the configured bound, while outgoing responses and events use bounded
backpressure.
procedure
(serve-fds input-fd output-fd [ #:max-pending-requests max-pending-requests #:max-outgoing-frames max-outgoing-frames]) → void? input-fd : exact-integer? output-fd : exact-integer? max-pending-requests : exact-positive-integer? = 1024 max-outgoing-frames : exact-positive-integer? = 64
Adapts native file descriptors to binary ports and calls serve.
procedure
(rpc-schema) → list?
Returns the registered RPC schema used by code generation.
procedure
(event-schema) → list?
Returns the registered event schema.
procedure
(state-schema) → list?
Returns the registered state schema.
procedure
(record-schema) → list?
Returns the registered Record schema.
procedure
(enum-schema) → list?
Returns the registered Enum schema.