We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2091fa7 commit 5c7114eCopy full SHA for 5c7114e
tokio/tests/task_local.rs
@@ -145,3 +145,27 @@ async fn poll_after_take_value_should_fail() {
145
// Poll the future after `take_value` has been called
146
fut.await;
147
}
148
+
149
+#[tokio::test]
150
+async fn get_value() {
151
+ tokio::task_local! {
152
+ static KEY: u32
153
+ }
154
155
+ KEY.scope(1, async {
156
+ assert_eq!(KEY.get(), 1);
157
+ assert_eq!(KEY.try_get().unwrap(), 1);
158
+ })
159
+ .await;
160
161
+ let fut = KEY.scope(1, async {
162
+ let result = KEY.try_get();
163
+ // The task local value no longer exists.
164
+ assert!(result.is_err());
165
+ });
166
+ let mut fut = Box::pin(fut);
167
+ fut.as_mut().take_value();
168
169
+ // Poll the future after `take_value` has been called
170
+ fut.await;
171
+}
0 commit comments