hundreds-father-404
02/11/2021, 5:10 PMBox
? I wrote this function signature:
pub async fn with_workunit<F>(
workunit_store: WorkunitStore,
name: String,
initial_metadata: WorkunitMetadata,
future_fn: Box<dyn FnOnce(&mut Workunit) -> F>,
) -> F::Output
where
F: Future,
{
In contrast, the old function has:
final_metadata_fn: for<'a> FnOnce(&'a F::Output, WorkunitMetadata) -> WorkunitMetadata
But when I try to do that, I get
error[E0277]: the size for values of type `(dyn for<'a, 'r> FnOnce(&'a &'r mut Workunit) -> F + 'static)` cannot be known at compilation time
--> workunit_store/src/lib.rs:821:3
|
821 | future_fn: for<'a> FnOnce(&'a &mut Workunit) -> F,
| ^^^^^^^^^ doesn't have a size known at compile-time
hundreds-breakfast-49010
02/11/2021, 5:13 PMhundreds-father-404
02/11/2021, 5:14 PMpub async fn with_workunit<F>(
workunit_store: WorkunitStore,
name: String,
initial_metadata: WorkunitMetadata,
future_fn: for<'a> FnOnce(&'a &mut Workunit) -> F,
) -> F::Output
where
F: Future,
hundreds-father-404
02/11/2021, 5:15 PMBox<dyn>
doesn't work:
`dyn for<'r> FnOnce(&'r mut Workunit) -> impl futures::Future` cannot be sent between threads safely
hundreds-father-404
02/11/2021, 5:19 PMpub async fn with_workunit<F>(
workunit_store: WorkunitStore,
name: String,
initial_metadata: WorkunitMetadata,
future_fn: impl FnOnce(&mut Workunit) -> F,
) -> F::Output
where
F: Future,
fast-nail-55400
02/11/2021, 6:02 PMfast-nail-55400
02/11/2021, 6:02 PM<http://name.as|name.as>_ref().to_owned()
? would be more ergonomic to not have to put .to_owned()
at all call siteswitty-crayon-22786
02/11/2021, 7:02 PMhundreds-father-404
02/11/2021, 7:04 PMwitty-crayon-22786
02/11/2021, 7:05 PMwitty-crayon-22786
02/11/2021, 7:06 PMwith_workunit
, where only the one that needs access to the workunit requires a boxed future, but.witty-crayon-22786
02/11/2021, 7:37 PMFn(InProgressWorkunit) -> Future<T>
which would be dynamically checked. the downside of the dynamic checking is that youād need to panic if somebody leaked the InProgressWorkunit
, which is not friendly.witty-crayon-22786
02/11/2021, 7:37 PMhundreds-father-404
02/11/2021, 7:38 PMhundreds-father-404
02/11/2021, 7:39 PMThe other would be to pass in a non-reference object likeĀ Fn(InProgressWorkunit) -> Future<T>This feels more similar to the final_metadata_fn idea, right? As long as we can call
InProgressWorkunit.increment_counter()
, sounds reasonablewitty-crayon-22786
02/11/2021, 7:56 PMwitty-crayon-22786
02/11/2021, 7:56 PMwitty-crayon-22786
02/11/2021, 8:04 PMtracing
hasnāt quite figure out yet either: https://docs.rs/tracing/0.1.23/tracing/span/struct.Span.html#in-asynchronous-codewitty-crayon-22786
02/11/2021, 8:06 PMin_scope
, your parent pointers are wrong.witty-crayon-22786
02/11/2021, 8:11 PMhundreds-father-404
02/11/2021, 8:15 PMthe downside of the dynamic checking is that youād need to panic if somebody leaked theĀ InProgressWorkunitĀ , which is not friendly.This should be deterministic, right? If it's something that us Pants devs will catch when dogfooding Pants day-to-day, I'm less concerned. If it's something we'll easily miss, then hm
should be deterministicReasoning about async blocks is tricky
witty-crayon-22786
02/11/2021, 8:21 PMThis should be deterministic, right? If itās something that us Pants devs will catch when dogfooding Pants day-to-day, Iām less concerned. If itās something weāll easily miss, then hmyea, thatās what i was thinking. but itās annoying because itās internally a bit magical. going to spend a bit more time on the
Box
approach, and weāll see.witty-crayon-22786
02/11/2021, 11:35 PMhundreds-father-404
02/11/2021, 11:46 PM