@@ -16,3 +16,62 @@ fn panic() {
16
16
panic ! ( "boom" ) ;
17
17
} ) ;
18
18
}
19
+
20
+ #[ cfg( feature = "unstable" ) ]
21
+ #[ test]
22
+ fn nested_block_on_local ( ) {
23
+ let x = task:: block_on ( async {
24
+ let a =
25
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 3 ) . await } ) } ) ;
26
+ let b = task:: spawn_local ( async {
27
+ task:: block_on ( async { async_std:: future:: ready ( 2 ) . await } )
28
+ } )
29
+ . await ;
30
+ let c =
31
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 1 ) . await } ) } ) ;
32
+ a + b + c
33
+ } ) ;
34
+
35
+ assert_eq ! ( x, 3 + 2 + 1 ) ;
36
+
37
+ let y = task:: block_on ( async {
38
+ let a =
39
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 3 ) . await } ) } ) ;
40
+ let b = task:: spawn_local ( async {
41
+ task:: block_on ( async { async_std:: future:: ready ( 2 ) . await } )
42
+ } )
43
+ . await ;
44
+ let c =
45
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 1 ) . await } ) } ) ;
46
+ a + b + c
47
+ } ) ;
48
+
49
+ assert_eq ! ( y, 3 + 2 + 1 ) ;
50
+ }
51
+
52
+ #[ test]
53
+ fn nested_block_on ( ) {
54
+ let x = task:: block_on ( async {
55
+ let a =
56
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 3 ) . await } ) } ) ;
57
+ let b =
58
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 2 ) . await } ) } ) ;
59
+ let c =
60
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 1 ) . await } ) } ) ;
61
+ a + b + c
62
+ } ) ;
63
+
64
+ assert_eq ! ( x, 3 + 2 + 1 ) ;
65
+
66
+ let y = task:: block_on ( async {
67
+ let a =
68
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 3 ) . await } ) } ) ;
69
+ let b =
70
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 2 ) . await } ) } ) ;
71
+ let c =
72
+ task:: block_on ( async { task:: block_on ( async { async_std:: future:: ready ( 1 ) . await } ) } ) ;
73
+ a + b + c
74
+ } ) ;
75
+
76
+ assert_eq ! ( y, 3 + 2 + 1 ) ;
77
+ }
0 commit comments