@@ -11,18 +11,18 @@ use tokio::task::{AbortHandle, JoinHandle, JoinSet};
1111use tokio:: time:: { Instant as TokioInstant , MissedTickBehavior } ;
1212use tokio_util:: time:: FutureExt as _;
1313
14- use crate :: time:: Duration ;
14+ use crate :: time:: LuaDuration ;
1515
1616#[ derive( Clone , Default ) ]
1717struct Params {
1818 name : Option < String > ,
19- timeout : Option < Duration > ,
19+ timeout : Option < LuaDuration > ,
2020}
2121
2222pub struct TaskHandle {
2323 name : Option < String > ,
2424 started : Rc < RefCell < Option < Instant > > > ,
25- elapsed : Rc < RefCell < Option < Duration > > > ,
25+ elapsed : Rc < RefCell < Option < LuaDuration > > > ,
2626 handle : Either < Option < JoinHandle < Result < Value > > > , AbortHandle > ,
2727}
2828
@@ -64,7 +64,7 @@ impl UserData for TaskHandle {
6464
6565 registry. add_method ( "elapsed" , |_, this, ( ) | match * this. elapsed . borrow ( ) {
6666 Some ( dur) => Ok ( Some ( dur) ) ,
67- None => Ok ( this. started . borrow ( ) . map ( |s| Duration ( s. elapsed ( ) ) ) ) ,
67+ None => Ok ( this. started . borrow ( ) . map ( |s| LuaDuration ( s. elapsed ( ) ) ) ) ,
6868 } ) ;
6969
7070 registry. add_method ( "is_finished" , |_, this, ( ) | match this. handle . as_ref ( ) {
@@ -83,7 +83,7 @@ pub struct Task {
8383impl Task {
8484 fn new ( func : Function , params : Option < Table > ) -> Result < Self > {
8585 let name: Option < String > = opt_param ! ( params, "name" ) ?;
86- let timeout: Option < Duration > = opt_param ! ( params, "timeout" ) ?;
86+ let timeout: Option < LuaDuration > = opt_param ! ( params, "timeout" ) ?;
8787 Ok ( Self {
8888 func,
8989 params : Params { name, timeout } ,
@@ -122,7 +122,7 @@ impl UserData for Group {
122122 let abort_handle = this. 0 . spawn_local ( async move {
123123 * started2. borrow_mut ( ) = Some ( Instant :: now ( ) ) ;
124124 defer ! {
125- * elapsed2. borrow_mut( ) = Some ( Duration ( started2. borrow( ) . unwrap( ) . elapsed( ) ) ) ;
125+ * elapsed2. borrow_mut( ) = Some ( LuaDuration ( started2. borrow( ) . unwrap( ) . elapsed( ) ) ) ;
126126 }
127127
128128 let result = match timeout {
@@ -191,7 +191,7 @@ fn spawn_inner(params: Params, fut: impl Future<Output = Result<Value>> + 'stati
191191 let handle = tokio:: task:: spawn_local ( async move {
192192 * started2. borrow_mut ( ) = Some ( Instant :: now ( ) ) ;
193193 defer ! {
194- * elapsed2. borrow_mut( ) = Some ( Duration ( started2. borrow( ) . unwrap( ) . elapsed( ) ) ) ;
194+ * elapsed2. borrow_mut( ) = Some ( LuaDuration ( started2. borrow( ) . unwrap( ) . elapsed( ) ) ) ;
195195 }
196196
197197 let result = match timeout {
@@ -226,7 +226,7 @@ pub fn spawn(_: &Lua, (func, args): (Either<Function, UserDataRef<Task>>, MultiV
226226
227227pub fn spawn_every (
228228 _: & Lua ,
229- ( dur, func, args) : ( Duration , Either < Function , UserDataRef < Task > > , MultiValue ) ,
229+ ( dur, func, args) : ( LuaDuration , Either < Function , UserDataRef < Task > > , MultiValue ) ,
230230) -> Result < TaskHandle > {
231231 let ( func, params) = match func {
232232 Either :: Left ( f) => ( f, Params :: default ( ) ) ,
@@ -243,7 +243,7 @@ pub fn spawn_every(
243243 } )
244244}
245245
246- pub async fn sleep ( _: Lua , dur : Duration ) -> Result < ( ) > {
246+ pub async fn sleep ( _: Lua , dur : LuaDuration ) -> Result < ( ) > {
247247 tokio:: time:: sleep ( dur. 0 ) . await ;
248248 Ok ( ( ) )
249249}
0 commit comments