結局タスクローカル領域へのアクセスはFutureとして提供してしまうのが(比較的)安全だという結論になった。それでもspawnされたFutureからアクセスするのを止められないという問題があるが…
-
Show this thread
-
fn with_get_cx<F>(f: F) -> impl Future<T, E> where f: FnMut(&mut Cx) -> Poll<T, E>, { poll_fn(|| { CX.with(f) }) }
1 reply 0 retweets 0 likesShow this thread -
async fn handler() { let parsed_query = await!(with_get_cx(|cx| { parse_request(cx.request()) }))?; }
1 reply 0 retweets 0 likesShow this thread -
非同期でない処理にawaitを要求するのは直感的ではない感があるが,エラーが実行時に吐かれるよりはまぁましな気もする
1 reply 0 retweets 0 likesShow this thread
async fn handler() { tokio_executor::spawn(lazy(|| { with_get_cx(|cx| { ... }) }) } と書ける可能性を排除できないが,これは「別スレッドからスレッドローカル変数にアクセスしようとしている」と同じパターンなのでそう書いた側にも責任があると言えば良さそう…
8:37 PM - 21 Jun 2018
0 replies
0 retweets
0 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.