1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! High-level async helper commands for common operations
//!
//! This module provides ergonomic helper functions for common async operations
//! like HTTP requests, WebSocket connections, and file I/O.
//!
//! ## Available Helpers
//!
//! ### HTTP Operations
//! Simple HTTP requests with automatic JSON handling:
//! ```no_run
//! # use hojicha_core::async_helpers::{http_get, http_post, HttpResponse, HttpError};
//! # use hojicha_core::Cmd;
//! # enum Msg { DataLoaded(String), Error(String), UserCreated(String) }
//! // GET request
//! let cmd: Cmd<Msg> = http_get("https://api.example.com/data", |result| {
//! match result {
//! Ok(response) => Msg::DataLoaded(response.body),
//! Err(err) => Msg::Error(err.to_string()),
//! }
//! });
//!
//! // POST with JSON body (as string)
//! let json_body = r#"{"name": "Alice"}"#;
//! let cmd = http_post(
//! "https://api.example.com/users",
//! json_body,
//! |result| match result {
//! Ok(response) => Msg::UserCreated(response.body),
//! Err(e) => Msg::Error(e.to_string()),
//! }
//! );
//! ```
//!
//! ### WebSocket Connections
//! Real-time bidirectional communication:
//! ```no_run
//! # use hojicha_core::async_helpers::{websocket, WebSocketEvent};
//! # use hojicha_core::Cmd;
//! # enum Msg { WsConnected, WsMessage(String), WsError(String), WsDisconnected, WsBinary(Vec<u8>) }
//! let cmd: Cmd<Msg> = websocket("wss://echo.websocket.org", |event| {
//! Some(match event {
//! WebSocketEvent::Connected => Msg::WsConnected,
//! WebSocketEvent::Message(text) => Msg::WsMessage(text),
//! WebSocketEvent::Binary(data) => Msg::WsBinary(data),
//! WebSocketEvent::Error(err) => Msg::WsError(err.to_string()),
//! WebSocketEvent::Closed(_) => Msg::WsDisconnected,
//! })
//! });
//! ```
//!
//! ### File Operations
//! Async file I/O and watching:
//! ```no_run
//! # use hojicha_core::async_helpers::{read_file, write_file, watch_file};
//! # use hojicha_core::Cmd;
//! # enum Msg { ConfigLoaded(String), Error(String), FileChanged }
//! // Read file
//! let cmd: Cmd<Msg> = read_file("config.json", |result| {
//! result.map(Msg::ConfigLoaded)
//! .unwrap_or_else(|e| Msg::Error(e.to_string()))
//! });
//!
//! // Watch for changes
//! let cmd = watch_file("data.csv", |_| Some(Msg::FileChanged));
//! ```
//!
//! ### Timers
//! Delays and intervals:
//! ```no_run
//! # use hojicha_core::async_helpers::{delay, interval};
//! # use hojicha_core::Cmd;
//! # use std::time::Duration;
//! # enum Msg { TimerExpired, Tick(usize) }
//! // One-shot delay
//! let cmd: Cmd<Msg> = delay(Duration::from_secs(2), || Msg::TimerExpired);
//!
//! // Repeating interval
//! let cmd = interval(Duration::from_secs(1), |count| Msg::Tick(count));
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
/// Result type for async operations
pub type AsyncResult<T> = ;
/// Common configuration for async operations
/// Backoff strategy for retries