• orclev@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    5 days ago

    In my opinion the two biggest problems with async today are that it’s missing a standardized API for spawning new threads/tasks (forcing you into picking a particular implementation for something that is pretty fundamental to using async), and there’s no convenient (to say nothing of standardized) way to pin metadata to a Future (E.G. an execution context, or thread-local equivalent). While you can certainly just pass an execution context object around manually it would be nice if there was something baked into Future itself that would prevent that context from cropping up in every method signature.

    The new nightly only (and feature flag gated) std::future::join! macro is a nice start, but there’s still more needed (E.G. a mechanism to signal to the underlying implementation that you would prefer some set of Futures be run in parallel if possible). It would also be nice to see a Future variant that supports the concept of retry/repeat out of the box, something like a RestartableFuture.

        • BB_C@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          5 days ago

          Stating the obvious: a trait is type class you implement for types. It’s not something you can “pin metadata” (or any data) to.

          • orclev@lemmy.world
            link
            fedilink
            arrow-up
            3
            ·
            5 days ago

            It’s an API, if you add methods to it then the implementations will support that. That is in fact the entire point of a trait.

            • BB_C@programming.dev
              link
              fedilink
              arrow-up
              1
              ·
              4 days ago
              struct SomeFuture;
              
              impl Future for SomeFuture {
                // ....
              }
              
              

              where are you going to “pin metadata”?

              • lad@programming.dev
                link
                fedilink
                English
                arrow-up
                3
                ·
                4 days ago

                I think, they mean:

                pub trait Future {
                  // ....
                
                  fn put_metadata(...);
                
                  fn get_metadata(...);
                }
                

                I find it too magical to be necessary, but I can see how it might be useful. This can be achieved with a wrapper, but will then require you to wrap every future, which is not too convenient

                • devnev@lemmy.dbzer0.com
                  link
                  fedilink
                  arrow-up
                  3
                  ·
                  4 days ago

                  Other languages have ended up introducing it out of practical necessity, e.g. Go’s contexts, JS execution contexts. Pick your poison, although I expect Rust’s general minimal approach will leave it as extra parameters, Go-style.

                  • orclev@lemmy.world
                    link
                    fedilink
                    arrow-up
                    3
                    ·
                    edit-2
                    4 days ago

                    You do realize FutureExt is a trait right? That’s literally what I’m asking for just with it baked into Future instead of FutureExt.