sprocket/cassette
Types
pub type CassetteOpts {
CassetteOpts(debug: Bool)
}
Constructors
-
CassetteOpts(debug: Bool)
pub type LiveService {
LiveService(
id: Unique,
on_msg: fn(String, Unique, fn(String) -> Result(Nil, Nil)) ->
Result(Nil, Nil),
on_init: fn(Unique) -> Result(Nil, Nil),
on_close: fn(Unique) -> Result(Nil, Nil),
)
}
Constructors
-
LiveService( id: Unique, on_msg: fn(String, Unique, fn(String) -> Result(Nil, Nil)) -> Result(Nil, Nil), on_init: fn(Unique) -> Result(Nil, Nil), on_close: fn(Unique) -> Result(Nil, Nil), )
pub type Message {
Shutdown
GetState(reply_with: Subject(State))
PushPreflight(preflight: Preflight)
CleanupPreflights
StartPreflightCleanupJob(cleanup_preflights: fn() -> Nil)
PopPreflight(
reply_with: Subject(Result(Preflight, Nil)),
id: String,
)
PushSprocket(sprocket: Sprocket)
GetSprocket(
reply_with: Subject(Result(Sprocket, Nil)),
ws: Unique,
)
PopSprocket(
reply_with: Subject(Result(Sprocket, Nil)),
ws: Unique,
)
}
Constructors
-
Shutdown
-
GetState(reply_with: Subject(State))
-
PushPreflight(preflight: Preflight)
-
CleanupPreflights
-
StartPreflightCleanupJob(cleanup_preflights: fn() -> Nil)
-
PopPreflight( reply_with: Subject(Result(Preflight, Nil)), id: String, )
-
PushSprocket(sprocket: Sprocket)
-
GetSprocket( reply_with: Subject(Result(Sprocket, Nil)), ws: Unique, )
-
PopSprocket( reply_with: Subject(Result(Sprocket, Nil)), ws: Unique, )
pub type Preflight {
Preflight(
id: String,
view: Element,
csrf_token: String,
created_at: Int,
)
}
Constructors
-
Preflight( id: String, view: Element, csrf_token: String, created_at: Int, )
Functions
pub fn get_state(ca: Subject(Message)) -> State
Get the current state of the cassette. Mostly intended for unit tests and debugging.
pub fn live_service(ca: Subject(Message)) -> LiveService
Returns a live service specification for a sprocket websocket.
This is a generic interface for handling websocket messages that can be used to implement a live service for a sprocket with a variety of different web servers.
Refer to the example docs repository for an example of how to use this.
pub fn pop_preflight(ca: Subject(Message), id: String) -> Result(
Preflight,
Nil,
)
Pops a preflight from the cassette.
pub fn push_preflight(ca: Subject(Message), preflight: Preflight) -> Preflight
Pushes a preflight to the cassette.
pub fn start(opts: Option(CassetteOpts)) -> Subject(Message)
Start the cassette. This is intended to only be called once during web server initiliazation.
The cassette is a long running process that manages the state of all sprockets and preflights.