Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86794

Add support of invoking QFuture continuations in a given context

    XMLWordPrintable

Details

    • Task
    • Resolution: Done
    • P2: Important
    • None
    • None
    • Core: Threads
    • None
    • 8
    • Qt6_Foundation_Sprint 23, Qt6_Foundation_Sprint 24

    Description

      It seems to be a common scenario when users want to invoke continuations only within a specific context. For example:

      static QFuture<void> DoSomething();
      
      ////
      struct Foo : public QObject {
          void doSomethingAndDoSomethingElse()
          {
              QPointer<Foo> self(this);
              DoSomething().then([self] {
                  if (self) {
                      // do something with self.
                      qDebug() << "Self is ok";
                  } else {
                      qDebug() << "Foo already deleted";
                  }
              });
          }
      };
      
      Foo *foo = new Foo;
      foo->doSomethingAndDoSomethingElse();
      // here foo gets deleted(by deleteLater for instance)
      

       
      If DoSomething() finishes after foo is destroyed, the continuation attached via .then() shouldn't be invoked. The above example solves the problem by capturing the context and checking if it's valid. But this solution doesn't scale well if there are multiple continuations attached, instead of just a single one.

      Another use-case is when the user needs to invoke the continuation in a specific object's context or thread.

      Add a way of specifying the execution context to be used when invoking continuations.

      For example;

      QObject *obj;
      
      future.then(object, [] {...})
      
      // or
      
      future.via(object).then([] {...})
      
      

       

      See also the discussion here.

      Attachments

        For Gerrit Dashboard: QTBUG-86794
        # Subject Branch Project Status CR V

        Activity

          People

            sonakur Sona Kurazyan
            sonakur Sona Kurazyan
            Maurice Kalinowski Maurice Kalinowski
            Alex Blasche Alex Blasche
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes