File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,19 @@ async fn test_async_function_wrap() -> Result<()> {
48
48
let res: String = lua. load ( r#"f("hello")"# ) . eval_async ( ) . await ?;
49
49
assert_eq ! ( res, "hello" ) ;
50
50
51
+ // Return error
52
+ let ferr = Function :: wrap_async ( || async move { Err :: < ( ) , _ > ( Error :: runtime ( "some async error" ) ) } ) ;
53
+ lua. globals ( ) . set ( "ferr" , ferr) ?;
54
+ lua. load (
55
+ r#"
56
+ local ok, err = pcall(ferr)
57
+ assert(not ok and tostring(err):find("some async error"))
58
+ "# ,
59
+ )
60
+ . exec_async ( )
61
+ . await
62
+ . unwrap ( ) ;
63
+
51
64
Ok ( ( ) )
52
65
}
53
66
@@ -376,6 +389,13 @@ async fn test_async_table_object_like() -> Result<()> {
376
389
table. set_metatable ( Some ( metatable) ) ;
377
390
assert_eq ! ( table. call_async:: <i64 >( ( ) ) . await . unwrap( ) , 15 ) ;
378
391
392
+ match table. call_async_method :: < ( ) > ( "non_existent" , ( ) ) . await {
393
+ Err ( Error :: RuntimeError ( err) ) => {
394
+ assert ! ( err. contains( "attempt to call a nil value (function 'non_existent')" ) )
395
+ }
396
+ r => panic ! ( "expected RuntimeError, got {r:?}" ) ,
397
+ }
398
+
379
399
Ok ( ( ) )
380
400
}
381
401
You can’t perform that action at this time.
0 commit comments