11use crate :: * ;
22use anyhow:: Result ;
33
4+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
5+ pub enum TimerAction {
6+ Debug ,
7+ SetTimer ( u64 ) ,
8+ }
9+
410/// Set a timer using the runtime that will return a Response after the specified duration.
511/// The duration should be a number of milliseconds.
612pub fn set_timer ( duration : u64 , context : Option < Context > ) {
@@ -11,7 +17,7 @@ pub fn set_timer(duration: u64, context: Option<Context>) {
1117 "our" ,
1218 ProcessId :: new ( Some ( "timer" ) , "distro" , "sys" ) ,
1319 ) )
14- . body ( duration. to_le_bytes ( ) )
20+ . body ( serde_json :: to_vec ( & TimerAction :: SetTimer ( duration) ) . unwrap ( ) )
1521 . expects_response ( ( duration / 1000 ) + 1 )
1622 // safe to unwrap this call when we know we've set both target and body
1723 . send ( )
@@ -23,7 +29,7 @@ pub fn set_timer(duration: u64, context: Option<Context>) {
2329 "our" ,
2430 ProcessId :: new ( Some ( "timer" ) , "distro" , "sys" ) ,
2531 ) )
26- . body ( duration. to_le_bytes ( ) )
32+ . body ( serde_json :: to_vec ( & TimerAction :: SetTimer ( duration) ) . unwrap ( ) )
2733 . expects_response ( ( duration / 1000 ) + 1 )
2834 . context ( context)
2935 // safe to unwrap this call when we know we've set both target and body
@@ -41,7 +47,7 @@ pub fn set_and_await_timer(duration: u64) -> Result<Message, SendError> {
4147 "our" ,
4248 ProcessId :: new ( Some ( "timer" ) , "distro" , "sys" ) ,
4349 ) )
44- . body ( duration. to_le_bytes ( ) )
50+ . body ( serde_json :: to_vec ( & TimerAction :: SetTimer ( duration) ) . unwrap ( ) )
4551 // safe to unwrap this call when we know we've set both target and body
4652 . send_and_await_response ( ( duration / 1000 ) + 1 )
4753 . unwrap ( )
0 commit comments