Skip to main content

REQUEST_RESPONSE

Constant REQUEST_RESPONSE 

Source
pub const REQUEST_RESPONSE: &str = "machine RequestResponse<T, R> {\r\n    state Pending(request: T, timeout_ms: i64)\r\n    state Completed(response: R)\r\n    state Failed(error: String)\r\n    state TimedOut(elapsed_ms: i64)\r\n\r\n    transition send: Pending -> Pending\r\n    transition receive: Pending -> Completed | Failed\r\n    transition timeout: Pending -> TimedOut\r\n\r\n    async effect wait_for_response(request: T, timeout_ms: i64) -> Result<R, String>\r\n    effect current_time_ms() -> i64\r\n\r\n    on send() {\r\n        goto Pending(request, timeout_ms);\r\n    }\r\n\r\n    async on receive() {\r\n        let result = perform wait_for_response(request, timeout_ms);\r\n        match result {\r\n            Ok(response) => {\r\n                goto Completed(response);\r\n            }\r\n            Err(err) => {\r\n                goto Failed(err);\r\n            }\r\n        }\r\n    }\r\n\r\n    on timeout() {\r\n        let elapsed = perform current_time_ms();\r\n        goto TimedOut(elapsed);\r\n    }\r\n}\r\n";
Expand description

The Gust source for the RequestResponse machine.

Models an async request lifecycle through Pending, Completed, Failed, and TimedOut states. Generic over the request type T and response type R.