Record · corpus.blog/posts/01a08789-803c-7129-942f-6f850cdfa8e0

Never Snooze a Future

jacko.io · published 2 March 2026

A record is what was published and who pointed at it. The text of the post is not held here: read it at the source, or at its Wayback capture.

3blogs citing
First cited
11 Apr 2026
Most recent
1 May 2026
Rank this month
not ranked
External links
68
Words captured
5,661

Cited by

Links from this post

Link
Host
https://play.rust-lang.org/?version=nightly&edition=2024&code=%23%21%5Bfeature%28gen_blocks%29%5D%0A%23%21%5Bfeature%28async_iterator%29%5D%0A%0Ause+std%3A%3Aasync_iter%3A%3AAsyncIterator%3B%0Ause+std%3A%3Apin%3A%3A%7BPin%2C+pin%7D%3B%0Ause+tokio%3A%3Async%3A%3Ampsc%3A%3AUnboundedReceiver%3B%0Ause+tokio%3A%3Atime%3A%3A%7BDuration%2C+sleep%7D%3B%0A%0A%2F%2F+a+helper+function+similar+to+%60StreamExt%3A%3Anext%60%0Afn+next%3CT%3E%28%0A++++mut+iter%3A+Pin%3C%26mut+impl+AsyncIterator%3CItem+%3D+T%3E%3E%2C%0A%29+-%3E+impl+Future%3COutput+%3D+Option%3CT%3E%3E+%7B%0A++++futures%3A%3Afuture%3A%3Apoll_fn%28move+%7Ccx%7C+iter.as_mut%28%29.poll_next%28cx%29%29%0A%7D%0A%0A%2F%2F+An+async+generator+function%21+As+of+December+2025%2C+this+syntax+is%0A%2F%2F+nightly-only.%0Aasync+gen+fn+double_each%28mut+channel%3A+UnboundedReceiver%3Ci32%3E%29+-%3E+i32+%7B%0A++++while+let+Some%28n%29+%3D+channel.recv%28%29.await+%7B%0A++++++++yield+2+*+n%3B%0A++++%7D%0A%7D%0A%0A%23%5Btokio%3A%3Amain%5D%0Aasync+fn+main%28%29+%7B%0A++++%2F%2F+Open+a+channel+and+spawn+a+background+task+that+sends+a+number+into%0A++++%2F%2F+it+every+second.%0A++++let+%28send%2C+recv%29+%3D+tokio%3A%3Async%3A%3Ampsc%3A%3Aunbounded_channel%28%29%3B%0A++++tokio%3A%3Aspawn%28async+move+%7B%0A++++++++for+i+in+1..%3D5+%7B%0A++++++++++++send.send%28i%29.unwrap%28%29%3B%0A++++++++++++sleep%28Duration%3A%3Afrom_secs%281%29%29.await%3B%0A++++++++%7D%0A++++%7D%29%3B%0A++++%2F%2F+Pass+the+receive+end+of+the+channel+to+an+%60async+gen%60+function+that%0A++++%2F%2F+doubles+each+element%2C+and+loop+over+the+results.%0A++++let+mut+stream+%3D+pin%21%28double_each%28recv%29%29%3B%0A++++while+let+Some%28n%29+%3D+next%28stream.as_mut%28%29%29.await+%7B%0A++++++++dbg%21%28n%29%3B%0A++++%7D%0A%7D
play.rust-lang.org
https://play.rust-lang.org/?edition=2024&code=use+std%3A%3Athread%3B%0Ause+std%3A%3Atime%3A%3ADuration%3B%0A%0Astatic+LOCK%3A+std%3A%3Async%3A%3AMutex%3C%28%29%3E+%3D+std%3A%3Async%3A%3AMutex%3A%3Anew%28%28%29%29%3B%0A%0Afn+foo%28%29+%7B%0A++++let+_guard+%3D+LOCK.lock%28%29.unwrap%28%29%3B%0A++++%2F%2F+Use+a+longer+sleep+in+this+example%2C+to+account+for+child+process%0A++++%2F%2F+spawning+time.%0A++++thread%3A%3Asleep%28Duration%3A%3Afrom_millis%281000%29%29%3B%0A%7D%0A%0Aextern+%22C%22+fn+foo_signal_handler%28_signum%3A+libc%3A%3Ac_int%29+%7B%0A++++%2F%2F+Printing+in+signal+handlers+isn%27t+really+allowed%2C+but+neither+is%0A++++%2F%2F+taking+locks%2C+in+part+because+of+exactly+the+sort+of+deadlocks+we%27re%0A++++%2F%2F+demonstrating+here.+It+works+in+this+case.%0A++++println%21%28%22We+make+it+here...%22%29%3B%0A++++foo%28%29%3B%0A++++println%21%28%22...but+not+here%21%22%29%3B%0A%7D%0A%0Afn+main%28%29+-%3E+std%3A%3Aio%3A%3AResult%3C%28%29%3E+%7B%0A++++%2F%2F+Set+a+signal+handler+for+SIGUSR1+that+calls+foo%28%29.%0A++++unsafe+%7B%0A++++++++libc%3A%3Asignal%28libc%3A%3ASIGUSR1%2C+foo_signal_handler+as+*const+%28%29+as+_%29%3B%0A++++%7D%0A++++%2F%2F+Spawn+a+child+process+that+sends+us+SIGUSR1+after+500+ms.%0A++++std%3A%3Aprocess%3A%3ACommand%3A%3Anew%28%22bash%22%29%0A++++++++.arg%28%22-c%22%29%0A++++++++.arg%28format%21%28%22sleep+0.5+%26%26+kill+-USR1+%7B%7D%22%2C+std%3A%3Aprocess%3A%3Aid%28%29%29%29%0A++++++++.spawn%28%29%3F%3B%0A++++%2F%2F+Call+%60foo%60+ourselves.+We%27ll+be+in+this+call+and+holding+%60LOCK%60+in%0A++++%2F%2F+%7E500+ms+when+SIGUSR1+arrives+and+the+signal+handler+fires.+It%27ll%0A++++%2F%2F+hijack+this+thread%2C+try+to+take+%60LOCK%60+again%2C+and+deadlock.%0A++++foo%28%29%3B%0A++++Ok%28%28%29%29%0A%7D
play.rust-lang.org
Elsewhere on jacko.io (1)